This is a migrated thread and some comments may be shown as answers.

Continuing Problems with Unbound GridView

5 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Phillip Hamlyn
Top achievements
Rank 1
Phillip Hamlyn asked on 05 Oct 2009, 03:22 PM
Hi,

I am struggling, after some days of effort, with a trivial implementation of an unbound grid.

Scenario: I have an unbound data object which I am using to populate an editable grid. When the user clicks on the "Add new row" I trap the DefaultValuesNeeded event and populate the grid cells with the default data required for that row. One of the columns is a calculated primary key, which I calculate and provide during the DefaultValuesNeeded event. (Previously I tried using the Row .Tag property but this has a similar problem to that described here).

1) The default values supplied are not visible in the row being edited.
2) When the CellEndEdit event fires, I want to copy the data from the edited cell into my underlying business object. However none of the default values I set for the row are available in the row Cells collection (including, unfortunately the primary key for the newly added row).

How can I use RadGridView to maintain an unbound list of data which has a calculated primary key, and default values ? I am really struggling with this, as it seems to be a really common thing to want to do ?

It would help if I could find a clear list of the events which fire when a row is added, in what order, and what they are intended to do - I may be missing something in the online help, but there doesn't seem to be a clear description. Irrespective of this, it seems that the magic "Add new row" feature is pretty broken if I cannot address the cells on the row during the CellEndEdit event ...

Frustrated.
Phillip

5 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 08 Oct 2009, 05:06 PM
Hi Phillip Hamlyn,

Thank you for writing.

I have to admit that we still has some issues with the usage of DefaultValuesNeeded event. That is the reason why you have experienced the strange behavior and unfortunately I cannot give you any suitable workaround. We will address it in some of the next releases. Please excuse us for the inconvenience. I have updated your Telerik points.

As to the process of copying data to your business object I think that the best place to do it is when the whole new row is confirmed and added to the grid. You can find how to track this process in the following KB Article.

Write me back if you have other questions.

Kind regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Phillip Hamlyn
Top achievements
Rank 1
answered on 09 Oct 2009, 10:11 AM
Hi,

Thanks for your honesty.

What I've done is to turn off the visibility of the "special" "add new row" functionality, and I now deliberately add a blank new row myself. I can therefore apply defaults to that row, and by checking the hidden primary key column (or row tag) I can tell when the user exits an editor for the row, whether this represents a new row to be added to my business object store or whether its an existing one that needs updating.

This is pretty straightforward but does have one disadvantage;
1) All grids need to be sorted because of an existing bug in the Telerik grid whereby new rows manually added are not made visible on the grid until some kind of grid sorting is carried out.
2) Becuase many of the fields in the blank new row are blank, or default values, the actual position of this row can be pretty random. Because of this on editable grids I have to load the data, sort the grid, turn off sorting, add the new row and then present it to the user. Consequently I cannot allow the user to sort an editable grid because their "new" row will bounce all over the place.

Phillip
0
Martin Vasilev
Telerik team
answered on 15 Oct 2009, 07:07 AM
Hi Phillip Hamlyn,

Thank you for getting back to me.

I think that you can use AddNewRow method to add a new row, populate its cells with needed default values, and afterward scroll to it to allow the end user to edit these values. In this case, you do not have to remove sorting, because the grid will find and scroll to the new row automatically. Please, consider the following code sample:

//create new row
GridViewDataRowInfo newRow = this.radGridView1.Rows.AddNew();
 
//add some default values
newRow.Cells[0].Value = this.radGridView1.Rows.Count + 1;
newRow.Cells[1].Value = "DefaultItem";
newRow.Cells[2].Value = "DefaultNumber";
 
//scrol to the new row and put it in edit mode
this.radGridView1.GridElement.ScrollToRow(newRow);
newRow.Cells[0].BeginEdit();

Hope this helps. Do not hesitate to write me back if need additional assistance.

All the best,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Phillip Hamlyn
Top achievements
Rank 1
answered on 15 Oct 2009, 07:49 AM
Martin,

I understand what your suggesting but;
1) This proposal would require an extra button on my user interface "Add new row" or some other way of getting the user to tell me that they want to add a new row
2) Not all the columns have default values - therefore once the row is added, again it will be in a random location becuase it will be automatically sorted to the new position. Agreed that I can position the Selected Row onto the new row, but its likely to be somewhere other than in a predictible place.

Because I'd need to have an "Add new row" button and because the positioning of the new row is not predictible, this would be a step backwards I think.

Phillip
0
Accepted
Martin Vasilev
Telerik team
answered on 21 Oct 2009, 07:26 AM
Hello Phillip Hamlyn,

I understand that my suggestion need additional UI elements, but unfortunately there is no easy and clean way to implement the add new row functionality integrated in the grid which is different than this one. Once again, please excuse us for the inconvenience.

Sincerely yours,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Phillip Hamlyn
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Phillip Hamlyn
Top achievements
Rank 1
Share this question
or