RadGridView Insert a new Row

5 posts, 0 answers
  1. Simon
    Simon avatar
    9 posts
    Member since:
    Feb 2015

    Posted 12 Dec 2018 Link to this post

    Hi,

    I'm working with the RadGridView component directly without use a model binding.

    I would like to add dynamically a new Row at a position in my grid view after an other row by using :

    gridView.Rows.Insert(row.Index + 1, newRow);

    It's working well if I'm not using a grouping. But when I add the grouping :

    GroupDescriptor descriptor = new GroupDescriptor();
    descriptor.GroupNames.Add("NomGroupe", ListSortDirection.Ascending);
    gridView.GroupDescriptors.Add(descriptor);

    It's not work because the Index is ordered by the groupe.

    How How can I do?

    Thanks for your help,

    Simon

  2. Dimitar
    Admin
    Dimitar avatar
    2902 posts

    Posted 12 Dec 2018 Link to this post

    Hi Simon,

    First, you need to make sure that the new row has the same value in the cell used for grouping. Then you need to take the index from the rows collection because the RowIndex property will return the index inside the group. Here is an example:
    private void button1_Click(object sender, EventArgs e)
    {
        var row = radGridView1.CurrentRow;
        var rowInfo = new GridViewDataRowInfo(this.radGridView1.MasterView);
        rowInfo.Cells[0].Value = "newRow";
        rowInfo.Cells[1].Value = "newRow";
        //group value
        rowInfo.Cells[2].Value = row.Cells["column3"].Value;
     
        var index = radGridView1.Rows.IndexOf(row);
        radGridView1.Rows.Insert(index + 1, rowInfo);
    }

    Detailed information about the indexes can be found here: Rows vs ChildRows.

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Simon
    Simon avatar
    9 posts
    Member since:
    Feb 2015

    Posted 12 Dec 2018 in reply to Dimitar Link to this post

    Thanks Dimitar, it's working.

    Regards,

    Simon

  4. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 27 May 2019 in reply to Dimitar Link to this post

    Hello Dimitar, 

    I would like to help me about RadGridView Winforms in C#.

    In my RadGridView, I created my columns. I have a list container (ex List<Product>) that I use in my radGridView.DataSource, so far no problems.

    In the RadGridView I have a column that represents the ID of my product. In the new row of the dataridview, I want to type an ID in this column and we search the article in DB. After I do not understand how I should do to display the information of the article found in the new row and continue to edit the other columns ?

    Thank you

     

  5. Dimitar
    Admin
    Dimitar avatar
    2902 posts

    Posted 28 May 2019 Link to this post

    Hi Fabrizio,

    You can use the CellEndEdit event to get the Id and populate the other cells. Here is an example of this:
    private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
    {
        if (e.Row is GridViewNewRowInfo && e.Column.Name == "ID")
        {
            var id = e.Row.Cells["ID"].Value.ToString();
            Console.WriteLine(id);
            e.Row.Cells["Name"].Value = "Test";
        }
    }

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top