I have a datagrid/gridview. I\'m populating the grid with 10 rows initially. On a button click every time,I\'m keeping on adding 10 rows to the datagrid/gridview. Now I want
Try this...
DataGridViewRow rowToSelect = this.dgvJobList.CurrentRow;
rowToSelect.Selected = true;
rowToSelect.Cells[0].Selected = true;
this.dgvJobList.CurrentCell = rowToSelect.Cells[0];
this.dgvJobList.BeginEdit(true);
For WinForms DataGridView:
myDataGridView.CurrentCell = myDataGridView.Rows[theRowIndex].Cells[0];
For WebForms GridView, use the SelectedIndex property
myGridView.SelectedIndex = theRowIndex;
Try this
dataGridView1.ClearSelection();
int nRowIndex = dataGridView1.Rows.Count - 1;
dataGridView1.Rows[nRowIndex].Selected = true;
dataGridView1.Rows[nRowIndex].Cells[0].Selected = true;
Try this, it's work for me
public static void ItemSetFocus(DataGrid Dg, int SelIndex)
{
if (Dg.Items.Count >= 1 && SelIndex < Dg.Items.Count)
{
Dg.ScrollIntoView(Dg.Items.GetItemAt(SelIndex));
Dg.SelectionMode = DataGridSelectionMode.Single;
Dg.SelectionUnit = DataGridSelectionUnit.FullRow;
Dg.SelectedIndex = SelIndex;
DataGridRow row = (DataGridRow)Dg.ItemContainerGenerator.ContainerFromIndex(SelIndex);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
}
Try this, I'm works well with below script snippet in Extjs 4.2.0.
//currentIndex is the index of grid row
var rowElement = this.getView().getRecord(currentIndex);
this.getView().focusRow(rowElement);
This post has been a god send. I am using VB in Visual Studio 2017 and just needed to go to the bottom of a DATAGRID to allow user to input data. By studying these answers I came up with this solution and thought others might find it useful.
Private Sub AddBUTTON_Click(sender As Object, e As RoutedEventArgs) Handles
AddBUTTON.Click
' Go to bottom to allow user to add item in last row
DataGrid.Focus()
DataGrid.UnselectAll()
DataGrid.SelectedIndex = 0
DataGrid.ScrollIntoView(DataGrid.SelectedItem)
Dim endofitems As Integer = DataGrid.Items.Count
DataGrid.ScrollIntoView(DataGrid.Items.GetItemAt(endofitems - 1))
End Sub