I had a similiar issue in a datagrid which I had to remember the value
and find it again. The scroll isn't readily available so I had to
override the normal grid to make the scroll accessible...
// When the frmEditShipment form closes, it will set the
// lastEvent and lastRecord strings so that we can
// this form can autonavigate to the record and re-select it.
// this way, even having several records open you can
// close anyone and be brought to it's matching line entry.
if(lastEvent == "Edit")
{
//lastEvent = "";
runData(true);
// runData has reset the grid, due to rebinding
// now set the grid back to the same location
// the BindingManagerBase gives you a link between
// the displayed records and the dataset records.
// use this to scroll to and select the row
BindingManagerBase bmb =
dgRec.BindingContext[dgRec.DataSource,"trucks"];
for(int i = 0; i < bmb.Count;i++)
{
// use the Manager as a cursor and move forward through it.
bmb.Position = i;
// check each row's barcode to see if it's the right one
DataRow dr = ((DataRowView)bmb.Current).Row;
if(lastRecord == Convert.ToString(dr["barCodeNumber"]))
{
// had to override the grid to get access to the scroll
// also had to use the overridden object as the grid,
// instead of the default Forms.DataGrid
// It now exists in MyDataGrid.cs
dgRec.ScrollToRow(i);
dgRec.CurrentCell = new DataGridCell(i,1);
dgRec.Select(i);
break; // don't look anymore
}
}
}
Maybe something similiar will help you get it working...
public class MyDataGrid : DataGrid
{
public MyDataGrid()
{
//
// TODO: Add constructor logic here
// This class is dirived from DataGrid to all
// the private method GridVScrolled to be
// accessed, allowing us to scroll the grid
// back to it's last row after a refresh
// of the data and a rebinding
//
}
public void ScrollToRow(int row)
{
if(this.DataSource != null)
{
this.GridVScrolled(this,new
ScrollEventArgs(ScrollEventType.LargeIncrement,row));
}
}
}