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
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
Thanks Dimitar, it's working.
Regards,
Simon
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
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