How to format drop down items in a datagridview combobox column

theskiguy

New member
Joined
Mar 18, 2013
Messages
1
Programming Experience
3-5
Hi Experts:

I have a bound datagridview with a combobox column that is unbound. The combobox column is unbound as this will only contain a list of percentages on 10% increments. The values in my database are stored in decimal format so like .80 for 80%. I also added the unbound values for the combobox the same way.

I have the datagridview column format set to "P0" to show percentage so when I refresh the grid, it shows 0.8 as 80 % exactly like I want. The issue I have is when I select the dropdown to pick a different percentage the list of available options that appear still show the decimal values and not the %'s. After selecting the value, it changes it to a percentage but I was wondering if there is anyway to get the dropdown items format to show %?

Thanks,
 
The dropdown is the editing control, which is a separate combobox control. Handle the grids EditingControlShowing event, where you check that you have the correct column, cast e.Control to type ComboBox and set its FormatString to "P0" as well.

Next problem is that the editing control will now return the formatted string value, so you must then handle the grids CellParsing event, where you parse the percent string from e.Value as number and divide by 100, then set e.Value and e.ParsingApplied=True.
 
Back
Top