Completed
Last Updated: 08 Oct 2019 11:19 by ADMIN
Release R3 2019 SP1
Syed Hussain
Created on: 19 Sep 2019 15:22
Category: GridView
Type: Bug Report
0
RadGridView: .Rows.Add return -1 in self-reference hierarchy

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. 

5 comments
ADMIN
Dess | Tech Support Engineer, Sr.
Posted on: 24 Sep 2019 07:33
Hello, Syed,  

According to the provided screenshot it seems that you need aself-referencing hierarchy. Indeed, in this case, the Rows.Add method doesn't return the expected index.

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

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.
Syed Hussain
Posted on: 23 Sep 2019 16:57

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. 

ADMIN
Dess | Tech Support Engineer, Sr.
Posted on: 23 Sep 2019 07:10

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

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.
Syed Hussain
Posted on: 20 Sep 2019 20:16

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.

 

 

Attached Files:
ADMIN
Dess | Tech Support Engineer, Sr.
Posted on: 20 Sep 2019 06:58
Hello, Syed,  

Note that RadGridView has been majorly refactored in 2010. All changes are listed in the release history: https://www.telerik.com/support/whats-new/winforms/release-history/q2-2010-(version-2010-2-10-713)

We strive to constantly improve the controls in the Telerik UI for WinForms suite. Hence, during the 9 years versions gap we have introduced numerous improvements all of which are listed in our release history: https://www.telerik.com/support/whats-new/winforms/release-history

Following the provided information, I was unable to reproduce the issue you are facing. The Row.Add method returns the index of the added row. The Add method is expected to return -1 if the adding operation is not successfully performed, e.g. the RowsChanging event is cancelled. 

I have attached my sample project. Could you please specify the exact steps how to reproduce the problem? Feel free to modify it in a way to reproduce the experienced issue and get back to me with it so I can investigate the precise case. Thank you in advance. 

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
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.
Attached Files: