Duplicated
Last Updated: 04 Feb 2025 14:28 by ADMIN
Martin
Created on: 06 Jan 2025 12:06
Category: UI for WinForms
Type: Bug Report
1
Parameter handling of GridViewRowCollection.Add(params object[] values) mismatch

This bug is about a mismatch between what behaviour is expected (on a functional level) and the actual behavior. There are different scenario's:

A normal example without a bug

int index = myRadGridView.Rows.Add(1, 2, 3); 

Actual and expected behavior

Adds a row to the grid, filling cells with the values 1, 2 and 3. Even when there are more columns than values, only the first 3 cells are filled.

Bug #1

int index = myRadGridView.Rows.Add(); // Will result in: myRadGridView.Rows.Add(new object[0]);

Actual behavior

IndexOutOfRangeException is thrown.

Expected behavior

A new row is added, the cells are not filled with anything, since it should not matter if 3, 4 or zero values are added to the cells. Or, if you are very strict, an ArgumentOutOfRangeException, telling us at least 1 value is required.

Remark

Of course there is also a NewRow() method. But that is no reason Add() should not be allowed to accept zero values.

Bug #2

int index = myRadGridView.Rows.Add((object[])null);

Actual behavior

A NullReferenceException is thrown. 

Expected behavior

ArgumentNullException, telling us that parameter "values" is not allowed to be null.

Bug #3

int index = myRadGridView.Rows.Add(new GridViewDataRowInfo(...), new GridViewDataRowInfo(...));

// or

int index = myRadGridView.Rows.Add(new object[] { new GridViewDataRowInfo(...), new GridViewDataRowInfo(...) });

Actual behavior

Only the first row is added. The second row, or even the second value (integer, string, whatever) is totally ignored. 

Expected behavior

  1. Or when a mixture of rows and values if given, an ArgumentException telling us that values and rows are not allowed to be mixed.
  2. Or when the values are all rows, all rows are added and the index of the last row is returned.
  3. Or an ArgumentException telling us that rows are not allowed to be added by this method and Add(GridViewDataRowInfo) or AddRange(GridViewDataRowInfo[]) are to be used.

Remark

The method Add(params object[] values) checks if the first value is a row, resulting in this and the previous bugs.

Duplicated
This item is a duplicate of an already existing item. You can find the original item here:
5 comments
ADMIN
Dinko | Tech Support Engineer
Posted on: 04 Feb 2025 14:28

Hi Martin,

You have a point here. I have also related the public feedback item so that it is more visible to the community. 

Regards,
Dinko | Tech Support Engineer
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.

Martin
Posted on: 04 Feb 2025 08:52
Just a formality... instead of "Declined", should it be "Duplicate"?
ADMIN
Dinko | Tech Support Engineer
Posted on: 08 Jan 2025 15:15

Hi Martin,

I have already related the internal backlog item to this one. I can assure you that the reported scenarios here will be considered when our team starts working on the item. I understand your point. Nevertheless, the exception is different, the scenario here is adding rows in unbound mode using different parameters of the Add() method. That is why we consider this as one just with different input. Currently, I can't confirm whether the green line mark in your post is wrong or right. This will be further investigated by our development team. Your feedback will be taken into account while refactoring the Add() method.

Regards,
Dinko | Tech Support Engineer
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.

Martin
Posted on: 08 Jan 2025 13:23

Hi Dinko,

Thanks for your fast evaluation.

Be aware that this report is a different method than the one described in https://feedback.telerik.com/winforms/1674889-radgridview-null-handling-for-gridviewrowcollection-add-gridviewrowinfo-item-unexpected. And the behavior looks the same but is slightly different, and happens in different parts of the code, so the fix could be different.

If you decide to put both bugreports together, then at least mention this method in the other bug so that both methods are fixed.

So far my general reaction.

The first few lines in Add(params object[] values) is this:

    public int Add(params object[] values)
    {
      if (this.owner.IsVirtualRows)
        return -1;
      if (values[0] is GridViewRowInfo gridViewRowInfo1) // <-- This is wrong
      {
        this.Add(gridViewRowInfo1);
        return gridViewRowInfo1.Index;
      }

The green line is the cause or the start of all described issues. It assumes values it not null. It also assumes that the array is filled with at least 1 value. Both assumptions can lead to a crash.

Furthermore, if the condition in the green line is true, all other extra values in the array (values[1], values[2], etc.) are ignored, if present. Which i.m.o. is weird. You are totally right that AddRange is a better choice in this scenario, but since one of your programmers wanted this method to support to add a row, he causes these side effects. 

In my opinion, this Add(params object[] values) function should never have allowed to add a row. To add a row you can use Add(GridViewRowInfo row) or AddRange(...). But it is not up to me to dictate policy to you. But I do want to let you know that the current implementation is inconsistent and buggy. 

In relation to the other bug: The green line of code does not appear in Add(GridViewRowInfo row), that is why I created a different bug report.

ADMIN
Dinko | Tech Support Engineer
Posted on: 08 Jan 2025 12:08

Hi Martin,

Let me try to follow the reported behaviors below:

Bug 1:

This behavior is related to the one that we have already discussed: RadGridView: Null handling for GridViewRowCollection.Add(GridViewRowInfo item) unexpected. Null values will be restricted and not allowed.

Bug 2:

Again, this is related to the one above. Null values will be handled and an exception will be thrown.

Bug 3:

The Add(params object[] values) method will add one row with the values specified as a parameter. Specifying multiple data rows as a parameter to this method will consider this as one row and won't iterate the passed array of rows. This approach is not supported. In general, you can use the AddRange() method and pass the rows with coma. Still, I will add this scenario to the RadGridView: Null handling for GridViewRowCollection.Add(GridViewRowInfo item) unexpected so that the development team could consider handling it while modifying the method.

Regards,
Dinko | Tech Support Engineer
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.