Create new row on commandcolumn click

3 posts, 0 answers
  1. Ellis
    Ellis avatar
    28 posts
    Member since:
    Jun 2007

    Posted 16 Jun 2010 Link to this post

     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

  2. Nikolay
    Nikolay avatar
    1805 posts

    Posted 21 Jun 2010 Link to this post

    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
            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")
            ' real id value
            Me.radGridView1.ActiveEditor.Value = "555"
        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.

    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
  3. Ellis
    Ellis avatar
    28 posts
    Member since:
    Jun 2007

    Posted 21 Jun 2010 Link to this post

    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.

Back to Top