sort option c# . net by column
Hi , Im new to datagridview basically , I have been successfull so far. Now im trying to add the option to sort by column ascending and descending , can someone assist me
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
David SmithPosted Feb 21, 2010, 9:55 AM
David SmithPosted Feb 21, 2010, 9:44 AM
Question someone, now I want to be able to have the option to hide and unhide columns and rows and also have the ability to add highlight and color multiple rows and columns
can someone point me in the right direction?
David SmithPosted Feb 21, 2010, 4:00 AM
kiran kumarPosted Feb 21, 2010, 12:44 AM
Kirtan PatelPosted Feb 21, 2010, 12:41 AM
Sam HobbsPosted Feb 21, 2010, 12:35 AM
dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.Automatic;
That's all you need to do, probably; if that does not work, then you probably need to remove other code that you have added to try to get it to work. Sometimes we expect something to be difficult and end up doing it a way that is more difficult than it needs to be.
David SmithPosted Feb 20, 2010, 11:42 PM
Karan PatelPosted Feb 20, 2010, 11:23 PM
David SmithPosted Feb 20, 2010, 11:00 PM
How do I fix that option
this.dataGridView1.Sort(dataGridView1.Columns[2],System.ComponentModel.ListSortDirection.Descending);
this.dataGridView1.Sort(dataGridView1.Columns[2],System.ComponentModel.ListSortDirection.Ascending);
this piece of code actually added the arrow to sort, but as soon as i hit the sort button it populated the error.
David SmithPosted Feb 20, 2010, 10:46 PM
kiran kumarPosted Feb 20, 2010, 10:27 PM
if you want sort the coloumn in descending order you can use this
this.dataGridView1.Sort(dataGridView1.Columns[int index],System.ComponentModel.ListSortDirection.Descending);
//index refers to your column no
if you want sort the coloumn in ascending order you can use this
this.dataGridView1.Sort(dataGridView1.Columns[int index],System.ComponentModel.ListSortDirection.Ascending);
//index refers to your coloumn no
mark the answer if it helps you