We have upgraded from WinControl UI 2010 to 2019 R2.
we have a lot of non-data bound radgridview that we process our data and add each row manually.
The radgridView.Rows.Add(rowdatacolumn1, rowdatacolumn2, rowdatacolumn3) used to return the row index of the added row. It is now returning -1 .
This is breaking a lot of our code.
I have logged it in our feedback portal by making this thread public. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.
I have also updated your Telerik points.
Currently, the possible solution that I can suggest is to extract the index after the row is added by the Rows.IndexOf(row) property value.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
We have defined the Master Template for both the parent and child template in the GridViewRelations because they are simply the same with the same column names and data type. To answer your question, yes we are using the grid to display hierarchy. Please see the attached screenshot:
In my simple example, we are just adding the Parent rows into the grid expecting returning index of the parent. We have not need to add any child data to show you the issue at hand.
Hello, Syed,
The provided sample project is greatly appreciated. I have noticed that you define a GridViewRelation where the parent and child templates are specified to be equal - the MasterTemplate in RadGridView. What is the purpose of defining such a relation? Usually, GridViewRelations are defined when you setup a hierarchical grid. Thus, the relation specifies the MasterTemplate and the child template that is added to the grid. But I haven't noticed any child template defined in the grid. If you are trying to define a hierarchy, please refer to the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-programmatically
When I remove the GridViewRelation, the row's index value is returned as expected. Please refer to the following code snippet, demonstrating how the Index property of the row is returned:
public virtual int Index
{
get
{
if (this.Parent != null)
{
return this.Parent.ChildRows.IndexOf(this);
}
if (this.IsAttached)
{
return this.ViewTemplate.ChildRows.IndexOf(this);
}
return -1;
}
}
If a relation exists, it is expected that a hierarchy is defined in the grid and the first 'if' statement is executed. However, the Parent.ChildRows collection doesn't contain the record since there is no hierarchy. Feel free to remove the relation in case no hierarchy is properly setup. Then, the row's Index will be returned as expected.
Should you have further questions please let me know.Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Hello,
Attached is a test project I just wrote on the fly to replicate the issue.
Please see the function addARow at line 41 on Form1.cs. Please check the variable ronum at line 46 after a row has been added. The row data appears to be in the Rows collection of the RadGridView. The return value setting the variable ronum is -1
subsequently, we are using the return index to get the tag of the newly added row to place an object inside which result in failure.
There is also an alternate function we have tested to be working but we don't want to resort to that method.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik