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

RadGridView Insert a new Row

4 Answers 2828 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 12 Dec 2018, 10:24 AM

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

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Dec 2018, 11:35 AM
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.
0
Simon
Top achievements
Rank 1
answered on 12 Dec 2018, 01:22 PM

Thanks Dimitar, it's working.

Regards,

Simon

0
Fabrizio
Top achievements
Rank 1
answered on 27 May 2019, 12:16 PM

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

 

0
Dimitar
Telerik team
answered on 28 May 2019, 06:58 AM
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.
Tags
GridView
Asked by
Simon
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Simon
Top achievements
Rank 1
Fabrizio
Top achievements
Rank 1
Share this question
or