Hello,
In the code behind, I select the last row in the grid.
var selectedRows = this.webDataGrid.Behaviors.Selection.SelectedRows;selectedRows.Add(this.webDataGrid.Rows[rowIndex]);
The row is selected but I don't see it because of the scroll pane.
How to automatically scroll to the selected row?
Thanks.
Hello schartrand ,
Thank you for posting in our forum.
There’s no way to set the scroll position on the server side but you could handle the client side Initialize event and in it get the selected row. Then you could scroll that row into view using the cell’s
scrollToView method. For example:
function WebDataGrid1_Grid_Initialize(sender, eventArgs)
{
var row = sender.get_behaviors().get_selection().get_selectedRows().getItem(0);
row.get_cell(0).scrollToView();
}
Let me know if you have any questions or concerns.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
http://es.infragistics.com/support
I am using your suggested method but it does not seem to work. I have added a new row. After that, I would like to select the newly added row and set the scrollbar to let users to see the selected row. What would be the possible reason that this does not work?
I had Activation behavior enabled.
Code behind:
protected void GridView1_OnRowAdded(object sender, RowAddedEventArgs e)
{ GridView1.ClearDataSource(); GridView1.DataSourceID = "ModelsDS"; GridView1.DataBind(); GridView1.Behaviors.Selection.SelectedRows.Clear(); GridView1.Behaviors.Selection.SelectedRows.Add(GridView1.Rows[GridView1.Rows.Count - 1]); }
Client side:
function GridView1_Initialize(sender, eventArgs) { try { var selectedRow = sender.get_behaviors().get_selection().get_selectedRows().getItem(0); selectedRow.get_cell(0).scrollToView(); } catch (e) { alert("Javascript error: GridView1_Initialize:\t" + e.message); } }