Add new row e.row.DataBoundItem is null

6 posts, 0 answers
  1. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 03 Aug 2010 Link to this post

    I have just realized that at CellValidating event e.row.DataBoundItem is allways null.
    In Q1 2010 when I added a new row into the grid using add row, e.row.DataBoundItem wasn't null and contained a new entity with part filled properties.
    Now my application fires many exceptions....

    Is it a bug or feature?
  2. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 03 Aug 2010 Link to this post

    Just catched an interesting moment.
    At RowValidating when I try to enter a new row e.RowIndex == -2
    How can it be?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 03 Aug 2010 Link to this post

    I'm really disappointed with Q2. If i will not fix all the bugs till 7AM, I will return back to Q1
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 04 Aug 2010 Link to this post

    Hello Alexander Panfilenok,

    Thank you for this question. 

    As I said in your support ticket this is a desired change. We modified the new row behavior and now you should set directly row values. It is no longer needed to use the DataBoundItem property. The RowIndex property is valid only for data rows.  

    I understand your concerns about our new version. Yes, it contains breaking changes, however we tried to keep them at minimum. We redesigned most of the code and provided many new features. If you could send us your application (in a new support ticket), we will do the transition to the new version for you.

    I  am looking forward to your reply.

    Sincerely yours,
    Jack
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Nick Gebbett
    Nick Gebbett avatar
    13 posts
    Member since:
    May 2010

    Posted 05 Aug 2010 Link to this post

    Thanks, I think i resolved the issue at least in first step.
    In future I will refactor this to something better looking.

    In the past I used CellValidationEvent to bind grid databound item to a local variable and if validation at Cell validation is ok and Row validation event is also ok, then save this variable to a database.

            void BaseGridView_CellValidating(object sender, CellValidatingEventArgs e)
            {
                if (e.Row == null) return;
                e.Row.ErrorText = String.Empty;
                if (BaseGridView.IsInEditMode && ((GridViewDataColumn)(e.Column)).FieldName != SelectFieldName)
                {
                    e.Cancel = false;
                    switch (((GridViewDataColumn)(e.Column)).FieldName)
                    {
                        case "Name":
                            InvokeValidateEvent(new ValidationEventArgs(new WarehouseType() { Id = ((WarehouseType)e.Row.DataBoundItem).Id }, "Name", e.Value));
                            break;
                        case "Description":
                            InvokeValidateEvent(new ValidationEventArgs(new WarehouseType(), "Description", e.Value));
                            break;
                    }
                    if (Errors.Any())
                    {
                        e.Cancel = true;
                        e.Row.ErrorText = Errors.ToList()[0].Message;
                    }
                    else
                    {
                        ThereIsEntityToSave = true;
                        Entity = (WarehouseType)e.Row.DataBoundItem;
                    }
                }
                BaseGridView.Refresh();
            }
    During validation I had to create a new istance to make ESC button working currectly. (when user wants to restore the previous cell value)

    Now, when databound item is null when a new row creating, I set the batabound item by code like this
                    if (e.Row.Index < 0)
                    {
                        if (e.Row.DataBoundItem == null)
                            e.Row.DataBoundItem = new WarehouseType();
                        NewRowAdding = true;
                    }
                    else
                    {
                        NewRowAdding = false;
                    }
    and as validation doesn't bind e.value to a databounditem I use the line like this
                        case "Name":
                            InvokeValidateEvent(new ValidationEventArgs(new WarehouseType() { Id = ((WarehouseType)e.Row.DataBoundItem).Id }, "Name", e.Value));
                            if (NewRowAdding) ((WarehouseType)e.Row.DataBoundItem).Name = (String)e.Value;
                            break;
    At the end I have noticed that some of the properties (that are selected using GridViewComboBoxColumn) are not displaying in the grid right after new row adding.

    I used UserAddedRow and UserAddingRow events to find that.

    During UserAddingRow all properties are ok but at UserAddedRow the properties, that were selected using GridViewComboBoxColumn are null,

    I have fixed this in this way

            void BaseGridView_UserAddedRow(object sender, GridViewRowEventArgs e)
            {
                e.Row.DataBoundItem = Entity;
            }

    where Entity is my local variable to save.

    Thanks and sorry about my previous posts, I was a little bit angry =) I think this is understandable.
  7. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 10 Aug 2010 Link to this post

    Hi Alexander Panfilenok,

    I am glad to hear that the issue is solved now. Do not hesitate to contact me back if you have further questions or issues.

    Regards,
    Julian Benkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready