I have been joining csdn for a while and have never written anything on my blog. Today, I am weak enough to write a simple question about my learning, this is just for the kids shoes that are just like me it cainiao, so you don't have to read them. When binding data, if you do not want to use an SQL statement to sort the bound data, you want to use the sort method of dataview. In winform, The datagridview is sorted by a column. Although it is simple, I hope you do not make a brick. After all, it is also knowledge. This method does not need to write the sorting code by yourself. You only need to set the sort attribute of defaultable's custom view defaultview to sort the fields you want to sort when binding data, you can set not only one column, but also multiple columns. This sorting method is actually the sort method of dataview, which is completed by fast sorting. A simple example is provided,
Sort by Column
Datatable dt = new datatable ();
String selsql = string. Format ("select serialnum as serial number, patientname as patient name, checkdate as check date from checkrecord ");
// Sort by the check date column. Here is just an alias for the checkdate name. If you do not have an alias DT. defaultview. Sort = "checkdate ";
Dt = business. BLL. runsqldataset (selsql). Tables [0];
DT. defaultview. Sort = "check date ASC ";
This. dgv_patientname.datasource = DT;
Sort by multiple columns. They are all the same. Column fields are separated by commas.
Datatable dt = new datatable ();
String selsql = string. Format ("select serialnum as serial number, patientname as patient name, checkdate as check date from checkrecord ");
// Sort the two columns by the serial number and check the date
Dt = business. BLL. runsqldataset (selsql). Tables [0];
DT. defaultview. Sort = "serial number ASC, check date ASC ";
This. dgv_patientname.datasource = DT;
In short, you can sort by which column or which column you want, and sometimes the SQL statement is too long to be sorted by using the above method, and this is suitable for Multiple Data Control bindings.