Rows can not be add programmatically added to the rad radgridview's Rows collectionwhen the control is data-bound

1 Answer 41 Views
GridView
Hamid
Top achievements
Rank 1
Hamid asked on 08 Mar 2022, 05:19 AM

Hi

After fetching information from the database and performing calculations, I want to add the information to the data grade view.
I have already made the columns based on the data type
I get this error when running the program:

"Rows can not be add programmatically added to the rad radgridview's  Rows collection when the control is data-bound"

This error does not always occur and it happens by accident

Whatever I searched for, I did not find the reason

Maybe my solution to this is wrong

Thank you in advance for your support

 

This code snippet is inside a loop and may run hundreds of times :

var item = new GridViewDataRowInfo(dailyGridView.MasterView);

                        if (dailyGridView.Columns.Any(c => c.Name == "Code"))
                            item.Cells["Code"].Value = personelInfo.First().Code;
                        if (dailyGridView.Columns.Any(c => c.Name == "FirstName"))
                            item.Cells["FirstName"].Value = personelInfo.First().FirstName;
                        if (dailyGridView.Columns.Any(c => c.Name == "LastName"))
                            item.Cells["LastName"].Value = personelInfo.First().LastName;
                        if (dailyGridView.Columns.Any(c => c.Name == "Date"))
                            item.Cells["Date"].Value = PersianDateTime.FromDateTime(report.Date).ToShortDateString();
                        if (dailyGridView.Columns.Any(c => c.Name == "DayName"))
                            item.Cells["DayName"].Value = PersianDateTime.FromDateTime(report.Date).DayName;
And more line ...


dailyGridView.Rows.Add(item);

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Mar 2022, 11:02 AM
Hello, Hamid,

When RadGridView is used in bound mode, it is necessary to add new records directly to the applied DataSource collection. Thus, RadGridView will be updated automatically. More information on this topic is available in the following article:
https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/reflecting-custom-object-changes-in-rgv 

The RadGridView.Rows collection should be managed only in unbound mode:
https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/unbound-mode 

Feel free to use this approach which suits your requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Hamid
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or