日期:2014-05-18  浏览次数:20999 次

datagrid与dataset排序不同时怎么抓数据
当datagrid与dataset排序不同时,我要怎么顺利的在datagrid中点选而抓取到dataset中正确row的值

------解决方案--------------------
用的datatable.dataview属性的抓取。
------解决方案--------------------
http://blog.csdn.net/baihe_591/archive/2008/05/19/2458715.aspx
------解决方案--------------------
this.datagrid1.DataSourse=ds.Tables[0].DefaultView;
 ds.Tables[0].DefaultView.ListChanged += new ListChangedEventHandler(DefaultView_ListChanged);
void DefaultView_ListChanged(object sender, ListChangedEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
this.dataGrid1_CurrentCellChanged(sender, e);
}
这样就能解决datagrid重新排序后,显示同步了.
------解决方案--------------------
DataGrid默认绑定的是datatable.DefaultView属性,该属性是DataView类型,只要搜索DataView就可以了。


//基于WindowsForms
取出DataGrid当前行绑定的DataTable的值。

如果DataRowView drv = (DataRowView)this.BindingContext[this.ds,this.ds.Tables[0].TableName].Current;
获取到drv就可以改数据,
DataRow dw = drv.Row; // 得到DataRow,
string s = dw["col1"].ToString();//想得到某一列的值
DataTable dt = dw.Table;//得到DataTable
DataSet ds = dt.DataSet;
如果需要更多的资料可以看这里,
http://www.syncfusion.com/FAQ/windowsforms/faq_c44c.aspx
------解决方案--------------------
DefaultView属性