Click here to Skip to main content
15,884,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to put separator in datagridview column ...I used below code for doing that ...

datagridview.Columns("Column").DefaultCellStyle.Format="##,0"

This acts like ---> 123456 : 123,456

but when I'm editing the cell and change the value to something else the separator will be removed and it'll be just number ... plz help me
Posted
Comments
Madhu Nair 11-Nov-13 7:52am    
In Windows or Web Application?

1 solution

Set the column data type.
VB
DataGridView1.Columns(0).ValueType = GetType(Double) ' or Integer, Single, etc.
DataGridView1.Columns(0).DefaultCellStyle.Format = "N0" ' N(zero) for no digits to the right of the decimal mark

Replace "Columns(0)" with the appropriate column designation for your application.
 
Share this answer
 
Comments
marimir 12-Nov-13 7:04am    
Thank you TnTinMn
But with your code the separator will be removed after edit..
TnTinMn 12-Nov-13 13:52pm    
How to you fill the DataGridView with values? Please show your code.

You could use the the DataGridView.CellEndEdit event to correct the format, but that is a hack that does not address the underlying issuem that I suspect is that you are filling a column that should be a numeric type with strings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900