在datagridview的顶部对新记录进行排序 [英] Sort new record on the top of datagridview
本文介绍了在datagridview的顶部对新记录进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在datagridview的顶部对我添加的记录进行排序。我尝试了一些方法对它进行排序,但它没有任何功能。attn_id是数据库中的主键。 br />
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.
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);
}
当我运行上面的代码时显示错误!
Datagridview控件必须绑定到iBindingList要排序的对象
如何对记录进行排序?
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?
推荐答案
只需在下面编写代码添加到ur datagridview表中按钮...
dataGridView1.Sort(dataGridView1.Columns [attn_id],ListSortDirection.Descending);
just write below code on add into ur datagridview table button...
dataGridView1.Sort(dataGridView1.Columns["attn_id"], ListSortDirection.Descending);
这篇关于在datagridview的顶部对新记录进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文