Scrolling to a specific row

Jan 18, 2012 at 7:03 AM

I would like to scroll the sourcegrid to a specific row which is found based on the searching for a row following user input into a search box in the WinForm.

I can't find any method to do this, can anyone help?


Apr 4, 2012 at 7:47 AM

Maybe this is not the perfect method, but I found a method to focus an specific row in SourceGrid.DataGrid:

I had a similar issue, but in my case, I had to show a panel in the winform which reduce  the height available for the grid and then, the selected row becomes hidden. So I had to scroll down to the selected row.

There's my method:

// Get the rowIndex of the Selected DataRow
var rowIndex = dataGrid1.Rows.DataSourceRowToIndex(dataGrid1.SelectedDataRows[0]);
// New position to focus + 1 because of header's row
var position = new Position(rowIndex + 1, 0);
// Focus that position 
dataGrid1.Selection.Focus(position, true);

Hope this helps.