Datagridview - Sort Datagrid View Column With Numbers And Texts On Column Header Click?Feb 13, 2012
It seems that on clicking datagridview column header, the column will be automatically sorted based on the column type. I have a column showing some numbers. If column type is string, it sorts "1","20","3" into "1","20","3". If column type is double, it sorts into "1","3","20" which is the result that I want. However, there might be some erros in the numbers and error messages(text) will show in the cell instead of numbers. So I cannot set the column type as double. I want to ignore these error messages and sort all the numbers. How can I do this?
Also, I need to add some background colors to different rows in datagridview. So in the column header click event, I call the bkgColor Sub to achieve this. My question is that how can I override the sorting method in this event?
Private Sub DataGridView1_ColumnHeaderMouseClick(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick