Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,I wan to sort my added record on the top of datagridview.I had try a few way to sort it but it no function."attn_id"is a primary key in database.
C#
using (TMPB_attn_DAL dalObj = new TMPB_attn_DAL())
     {
      dataGridView1.DataSource = dalObj.GetRecords().Cast<TMPB_attn>().ToList();
      dataGridView1.Refresh();
      dataGridView1.Sort(dataGridView1.Columns["attn_id"],ListSortDirection.Descending);
     }

when i run the above code it show out error!
Datagridview control must be bound to an iBindingList object to be sorted
how can i sort the record?
Posted

1 solution

just write below code on add into ur datagridview table button...
dataGridView1.Sort(dataGridView1.Columns["attn_id"], ListSortDirection.Descending);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900