GRChandrashekar
asked on
Datagridview
Private Sub DgridKeyDown(sender As System.Object,
e As Windows.Forms.KeyEventArgs) Handles dgrid.KeyDown
Dim crRowIndex As Integer = dgrid.CurrentCell.RowIndex
If crRowIndex + 1 = dgrid.Rows.Count Then
Else
Dim row As DataGridViewRow = dgrid.SelectedRows(0)
Loadcontrolsfromgridview(row)
End If
End Sub
Private Sub Loadcontrolsfromgridview(row As DataGridViewRow)
_primarykey = 0
tbxdescription.Text = row.Cells("Description").Value
_primarykey = row.Cells("TitleID").Value
btnsave.Text = "Update [F2]"
End Sub
Hi,The Problem with above code is
1. unless I click on the circled place and press enter, the data wont get loaded in textbox.
2. Pressing enter should not move to next row in grid. Only arrow keys should be used to navigate.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Something wrong
I get error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I get error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
That seems to be unrelated to this. Do you know which line throws the error?
ASKER
This Line
Dim row As DataGridViewRow = dgrid.SelectedRows(0)
The moment i try to press down arrow it throws error
Dim row As DataGridViewRow = dgrid.SelectedRows(0)
The moment i try to press down arrow it throws error
>Dim row As DataGridViewRow = dgrid.SelectedRows(0)
That's because now row is selected. Add a check around this code
If dgrid.SelectedRows.Count > 0 Then
Dim row As DataGridViewRow = dgrid.SelectedRows(0)
...
End If
That's because now row is selected. Add a check around this code
If dgrid.SelectedRows.Count > 0 Then
Dim row As DataGridViewRow = dgrid.SelectedRows(0)
...
End If
ASKER
after this change updown arrow keys do not work for navigation and have to click on row and then enter to select :(
Then you need to select the first row if no row is currently selected because you want to move to next row of selected row when you press down arrow so if there is no selected row then which row you move to?
ASKER
DataGrid.JPG