This is a migrated thread and some comments may be shown as answers.

Create new row on commandcolumn click

2 Answers 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ellis
Top achievements
Rank 2
Ellis asked on 16 Jun 2010, 02:04 PM
Hi,
 probably someoneelse already ask it but i didn't find the right post.

In my grid the first column is a commandcolumn. I use it for open a modal form, to chose the Article from the Warehouse.
When i choose it, i update some columns, like price, max quantity, idarticle, etc
But if i try to insert a new row in this way, i got an error.
In a previous post: "the new row is created when one or more of editors in the new row are open for the first time".
I can't do this, because the first operation is to chose the Article.
How can i solve this problem? There is a way to fire the command it creates the row?

 
    Private Sub RadGridView1_CommandCellClick(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles RadGridView1.CommandCellClick 
' I chose the article from warehouse 
'... 
' Then i set data in row from selected article 
                RadGridView1.CurrentRow.Cells("IdArticle").Value = IdArticle 
                RadGridView1.CurrentRow.Cells("Quantity").Value = Quantity 
                RadGridView1.CurrentRow.Cells("Price").Value = Price 
                RadGridView1.CurrentRow.Cells("DataMovimento").Value = Date.Today 
        End If 
    End Sub 

Thank you

Ellis

2 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 21 Jun 2010, 09:48 AM
Hi Ellis,

Thank you for the question.

Please refer to the code snippet below. It demonstrates the API that you should use to set values for the new row:
Private Sub radGridView1_CommandCellClick(ByVal sender As Object, ByVal e As EventArgs)
    If TypeOf Me.radGridView1.CurrentRow Is GridViewNewRowInfo Then
        Me.radGridView1.MasterGridViewInfo.TableAddNewRow.InitializeNewRow()
        Dim newRow As GridViewRowInfo = Me.radGridView1.MasterGridViewInfo.TableAddNewRow
        ' some default id value
        newRow.Cells("Id").Value = 0
        newRow.Cells("Quantity").Value = 555
        newRow.Cells("Price").Value = 555
        newRow.Cells("Date").Value = DateTime.Now
        Me.radGridView1.CurrentColumn = Me.radGridView1.Columns("Id")
        Me.radGridView1.BeginEdit()
        ' real id value
        Me.radGridView1.ActiveEditor.Value = "555"
        Me.radGridView1.MasterGridViewInfo.TableAddNewRow.InvalidateRow()
    End If
End Sub

Please note that you should put RadGridView in edit mode setting the desired value to the active editor. Thus, RadGridView will become notified that there is a UI change in the new row and when you press the Enter key, the new row will be committed.

I hope this helps. If you have additional questions, feel free to contact me.

Greetings,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ellis
Top achievements
Rank 2
answered on 21 Jun 2010, 03:11 PM
Hi Telerik,
   thanks for your replay.

I'll try it and it works! In this way the row is created and the users can edit other cells values. Perfect ;)

Thanks for your help.

Ellis
Tags
GridView
Asked by
Ellis
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
Ellis
Top achievements
Rank 2
Share this question
or