Hi Peter,
Thanks for your feedback.
For the "move the selector", I assume that you mean select certain row in
DataGrid.
Currently, there is no way to get corresponding row in DataGrid to certain
DataRow in datasource. Because in the UI side, the end user may click the
column header to sort and change the row order.
To get what you want, I think we have to re-implement the search function.
We can loop through the DataGrid rows collection, then use
CurrencyManager.List to get the underlying datasource. Sample code listed
below:
private void button1_Click(object sender, System.EventArgs e)
{
for(int i=0;i<this.dataGrid1.VisibleRowCount-1;i++)
{
CurrencyManager cm =
(CurrencyManager)this.dataGrid1.BindingContext[this.dataGrid1.DataSource,
this.dataGrid1.DataMember];
DataRowView drv = cm.List[i] as DataRowView;
DataRow dr=drv.Row;
if(int.Parse(dr["column1"].ToString())==2)
{
this.dataGrid1.Select(i);
}
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt=new DataTable();
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));
for(int i=0;i<5;i++)
{
DataRow dr=dt.NewRow();
dr["column1"]=5-i;
dr["column2"]="item"+i.ToString();
dt.Rows.Add(dr);
}
this.dataGrid1.DataSource=dt;
}
Hope this helps
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.