Hi @Malik Asad Mahmood ,
I want that new row will be inserted as last row as ascending order and always new row insert after row which is inserted further
I make a test based on your code and the following code works for me.
Private dt As DataTable = New DataTable()
Private num As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.AllowUserToAddRows = False
dt.Columns.Add("c1")
dt.Columns.Add("c2")
dt.Rows.Add("A", 12)
dt.Rows.Add("B", 21)
DataGridView1.DataSource = dt
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = Keys.Enter Then
If DataGridView1.CurrentCell.ColumnIndex < DataGridView1.ColumnCount - 1 Then
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(DataGridView1.CurrentCell.ColumnIndex + 1)
Return True
Else
Try
If DataGridView1.CurrentCell.RowIndex + 1 = DataGridView1.Rows.Count Then
num += 1
Dim row As DataRow = dt.NewRow()
row(0) = num
row(1) = num
dt.Rows.Add(row)
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex + 1).Cells(0)
Return True
Else
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex + 1).Cells(0)
Return True
End If
Catch ex As ArgumentOutOfRangeException
Return True
End Try
End If
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Result of my test.
Could you provide more related code about your second question? It will help us make a test.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.