日期:2014-05-19  浏览次数:20684 次

困扰了N久的问题
请教一个困扰了N久的问题:

我在查询时用Filter属性筛选出姓名=张三的学生,然后显示在DataGrid中

string   filter   =   "姓名= '张三 ' ";
this.StudentBindingSource.Filter=filter;
this.StudentTableAdapter.Fill(this.dBDataSet.Student);
this.StudentDataGrid.DataSource=this.StudentBindingSource;

然后,我要取出DataGrid的CurrentRowIndex的StudentName的值:
string   studentName= " ";
studentName=
          this.dBDataSet.Tables[ "Student "].Rows[StudentDataGrid.CurrentRowIndex][ "StudentName "].ToString();

问题是:
DataGrid显示的是只有张三这条记录,但我Show出来的都是其它的记录。

我个人感觉是this.dBDataSet.Tables[ "Student "].Rows这里有问题。
有人知道怎么办?谢谢了。

------解决方案--------------------


DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "id = 1 ";
string studentName = " ";
studentName =this.ds.Tables[0].Rows[this.dataGridView1.CurrentRow.Index][ "Name "].ToString();
------解决方案--------------------
Filer不会过滤掉datatable.rows里面的内容,而邦定的时候其实是显示的是这个datatable的defaultview的内容。
明白?