Hello ...
How to get current index from gridview when it's a new row
i have tried this method ...
Dim baris As Integer = GridDetail.CurrentRow.Index
MsgBox(baris.ToString)
the results is always -1 when i click command cell at new row
Thanks
7 Answers, 1 is accepted
Hello, Hengky,
The CurrentRow.Index property gives the index of the current row in the active view. According to the provided information, it is not clear how exactly you add a new row. If you use the new row you can use the UserAddedRow event. This event fires when the user has finished adding a new row and the row is successfully added to the grid. In this event, you have access to the Row.Index.
Private Sub RadGridView1_UserAddedRow(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim index As Integer = e.Row.Index
End Sub
Here is another example, if you add a new row on a button click:
Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
radGridView1.Rows.Add(2, "Davolio", "Nancy", "Table", 1)
Dim index = Me.radGridView1.CurrentRow.Index
End Sub
RadGridView offers the CurrentRowChanged event as well. It fires when the current row has changed. Here you have access to the old row and the new current row. Feel free to use it if it is suitable for you.
Private Sub RadGridView1_CurrentRowChanged(ByVal sender As Object, ByVal e As CurrentRowChangedEventArgs)
Dim currentRowIndex = e.CurrentRow.Index
Dim oldRowIndex = e.OldRow.Index
End Sub
If the suggested solutions, however, do not help you I would kindly ask you to provide more information or code snippet how exactly you add rows in your grid.
I hope this information is useful. Let me know if I can assist you further.
Regards,
Nadya
Progress Telerik
Hai nadya .... thanks for reply
i will try it ...
tq so much for the solution
Hai Nadya ....
I have tried the solution you gave to me...
It doesn't what i mean ...
I want get a row index when have a new row
ex
I have 2 column ....
textboxcolumn and commandcellcolumn in gridview ....
when i have a new row ... everytime i click the commandcell it's always -1
Hello, Hengky,
Note, if you have a GridViewTextBoxColumn and GridViewCommandColumn in RadGridView and you use the new row to add a new record to the grid when you click on the new row it is normal the RadGridView1.CurrentRow.Index is -1. The row index for the GridViewNewRowInfo is -1 by default, to differentiate it from the other rows in the grid.
When you finalize editing the new row and commit it to the grid's rows collection, eg. by pressing Enter, then the row index of the newly added record changes, and this is expected behavior.
I attached a test project. Could you please refer to it and let me know if it differs from your set up.
Regards,
Nadya
Progress Telerik
Hai nadya..
i already tried the solution.. Its work fine . .
But thats not my solution...
I want if at a new row when it click on commandcell it will open a new form.. Contain a grid....
when it closed the from it will return to the grid and fill it ... For the current row
finally i found the solution for my self
just simple code
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
If baris = -1 Then
RadGridView1.Rows.Add("baru")
Else
RadGridView1.Rows(baris).Cells(0).Value = RadTextBox1.Text
End If
end sub
Hi, Hengky,
I am glad that you found a suitable solution for your case. According to the provided code snippet, it seems that you update the cell value in a data row. Checking if the row index is -1 is a valid approach if would like to update a cell value in a current data row.
Do not hesitate to contact us in case of further difficulties.
Regards,
Nadya
Progress Telerik