Winform DatagridView Numeric Column Sorting

前端 未结 6 1883
有刺的猬
有刺的猬 2021-02-06 05:26

I am using just a simple DataGridView to hold a bunch of data (Funny that).

I have decimals in a particular column. But when it comes to ordering by that decimal column

6条回答
  •  借酒劲吻你
    2021-02-06 06:16

    I had the same problem. I tried using the event handler as David Hall mentioned. I used the ValueType property when defining the DataGridView. It now sorts as doubles, no custom event handler code needed

    dataGridView1.Columns[int index].ValueType = typeof(double);
    

    You can also format the column using

    dataGridView2.Columns[int index].DefaultCellStyle.Format = string format;
    

提交回复
热议问题