We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Format cell with percent signal

Hi, I have an issue when display a double value into gird with percent signal, For Example: Value in database : "0.06". So I need display in Gird with value "6.0%" Please show me how to resolve this issue Thank in advance, Hoang

7 Replies

AD Administrator Syncfusion Team February 21, 2005 09:17 AM UTC

You set the style.CellValueType = typeof(double) and style.Format = "P1". Now, you have explicitly added GridBoundColumns using GridDataBoundGrid.GridBoundColumns.Add from code or have added them with the designer, you would use the grid.GridBoundColumns["colname"].StyleInfo to set these styles. If you have not explicitly added GridBoundColumns, you would use the grid.Binder.InternalColumns["colname"].StyleInfo to set these styles.


HD Hoang Dinh February 21, 2005 10:16 AM UTC

Yes, I am using Binder.InternalColumns[ColumnName] to set style. But still have some isues: 1/ the begin value in a cell is "6.0%", After I deleted 6 and change current value in this cell to "7.0%" and press tab --> Result: an error message show as "7.0% is not a valid value for Double" 2/ the begin value in a cell is "6.0%", After I deleted 6 and change current value in this cell to "7.0" and press tab --> Result: The value of the current cell change to "700.00%" --> How to control these issues? I need current value in that cell always is "7.0%" Thanks


AD Administrator Syncfusion Team February 21, 2005 11:05 AM UTC

Take a look at this forum thread. It has a sample using QueryCellFormattedText and SaveCellFormattedText to has special requirements like 7.0 being used as 7.0% instead of (excel-like) 7.0 being 700%. Using these events also should avoid the problem with your user typing 7%. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=17345


HD Hoang Dinh February 22, 2005 02:35 AM UTC

Thanks,I using QueryCellFormattedText and SaveCellFormattedText as your mentioned. It look good. But at the begining of my question. I have a value in datatable is "0.06", and I would like to show on the gird as "6.0%". After that, when I changed to new value "7.0%", I would like to save to datatable as "0.07".Because after I changed to new value "7.0%", I saw new value in datatable is "7.0". I expect this value is "0.07" Please help me to resolve this issue.


AD Administrator Syncfusion Team February 22, 2005 09:51 AM UTC

What are you doing in SaveCellFormattedText? You should change the 7.0% into .07 in that event.


HD Hoang Dinh February 22, 2005 12:29 PM UTC

Thanks, May I ask another issue? How to set focus on a cell? After user type a value into a cell, I must validate this cell to check whether or not the value in this cell is correct. If it is incorrect, I must set focus on this cell. User can not change to another cell except fill a correct value in this cell. Can you help me? Thank in advance,


AD Administrator Syncfusion Team February 22, 2005 02:24 PM UTC

Try handling the CurrentCellValidating event. In that event, if grid.CurrentCell.Renderer.ControlText holds an invalid value, the set e.Cancel = true. This will make it so your user cannot leave the cell. (You can also set grid.CurrentCell.ErrorMessage if you want a message to be displayed at this point.)

Loader.
Live Chat Icon For mobile
Up arrow icon