
Hello!
Was the meaning of GridCellElement.RowIndex property changed since 2009-Q3?
Please see the following code snippet:
01.
public
Form1()
02.
{
03.
InitializeComponent();
04.
05.
radGridView1.Columns.Add(
new
GridViewTextBoxColumn(
"Group"
));
06.
radGridView1.Columns.Add(
new
GridViewTextBoxColumn(
"RowIndex"
));
07.
08.
for
(
int
i = 0; i < 3; i++)
09.
radGridView1.Rows.Add(
"Group 1"
);
10.
for
(
int
i = 0; i < 3; i++)
11.
radGridView1.Rows.Add(
"Group 2"
);
12.
13.
radGridView1.MasterTemplate.GroupDescriptors.Add(
new
GroupDescriptor(
"Group"
));
14.
}
15.
16.
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
17.
{
18.
if
(e.CellElement.ColumnInfo.Name ==
"RowIndex"
)
19.
e.CellElement.Value = e.CellElement.RowIndex.ToString();
20.
}
I expect the following result:
Group 1
0
1
2
Group 2
3
4
5
But the result is:
Group 1
0
1
2
Group 2
0
1
2
It seems that the RowIndex is an index inside the group but not the entire grid. Could you please confirm this?
Is the following workaround correct?
1.
int
rowIndex = radGridView1.Rows.IndexOf(e.CellElement.RowInfo);
Thank you.
9 Answers, 1 is accepted

In my point of view it should be like this, because counting the rows inside the Group, not all the rows, but if you want it to behave like it did before you can use:
private
void
radGridView1_CellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"RowIndex"
&& radGridView1.GroupDescriptors.Count == 0)
e.CellElement.Value = e.CellElement.RowIndex.ToString();
}
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

Hello!
In 2010-Q3 I had the groups and the RowIndex counted all the rows in the grid. Now the same code works differently. There is no any note regarding this change in the change logs. The help for GridCellElement.RowIndex says "Returns the index of the cell in the GridViewRowInfo." which, IMHO, is not correct. So, I would think that this is a bug.
Sorry, but your code is useless. If there are groups in the grid, your code would just ignore such case and do nothing. It is not a solution.
Thank you.


Please try this:
private
void
radGridView1_CellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"RowIndex"
)
e.CellElement.Text = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(e.CellElement.RowInfo).ToString();
}
By using the Text property it will be faster, because it does not need to recalculate every time
Best Regards,
Emanuel Varga

Hello!
I had to reinstall old "RadControls for WinForms Q3 2009 SP1" to check again. Yes, it worked well. The RowIndex counted all the grid rows.
As I wrote in my first message, the workaround "int rowIndex = radGridView1.Rows.IndexOf(e.CellElement.RowInfo);" does work.
The question is - is it a bug (which will be fixed later), or is it a permanent change?
Thank you.

I believe this behavior will remain like this, because the grouped rows are creating a hierarchy in the grid automatically and such, the RowIndex will be determined by the rows in the current hierarchical view.
Best Regards,
Emanuel Varga

Hello!
In this case, IMHO, it should be noted as a breaking change.
Thank you.

If you have any more questions please just let me know, and if the question has been solved, please mark the question as answered, so that others can find the answers to their questions faster.
Best Regards,
Emanuel Varga
Yes, I confirm that this is a breaking change introduced in Q2 2010. In this release we changed many things in RadGridView and it looks like we let this change through. The current behavior of the RowIndex property which is to return the index relative to the parent collection for the row will remain constant in our future releases. We made this change because the new ChildRows collection is hierarchical. This means that when grouping is applied it contains only the first level of group rows. In order to access a row within a group, you should use the group's own ChildRows collection. We will update our release notes accordingly and I have updated your Telerik points for this report.
In case you need further assistance with this, please write back and I will be glad to help.
Best wishes,
Jack
the Telerik team