I have a datagridview that i bind from an sql table, in that dv i have those attributes: Id, Name and Price. When i set the SortMode of the Name Columns to Automatic and i click on the header of this column i can sort this dv based on the first letter of the Name, this way i can order products based on their first letters ( Acumulator, Boat, CocaCola, Engine etc).
Is there a way this thing to happen without clicking the header of the column Name. I am looking some code that will do this job when the form will load.
You can then change the numerical cell values into image display values in a handler for the DataGridView. CellFormatting event. In this case, setting the SortMode property to Automatic will enable your users to sort the column.
There's a method on the DataGridView called "Sort":
this.dataGridView1.Sort(this.dataGridView1.Columns["Name"], ListSortDirection.Ascending);
This will programmatically sort your datagridview.
dataGridView1.Sort(dataGridView1.Columns[0],ListSortDirection.Ascending);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With