Home Forums WinForms controls Xceed Grid for WinForms Forcing the datagrid to save edited data

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12657 |

    Using VB.NET. When the user enters info into the datagrid, I want him to be able to click a SAVE button to save the data without having to press the ENTER key after entering the data. Does anyone know how to force the grid to save data programatically?

    Thanks

    Imported from legacy forums. Posted by DimondWoof (had 7477 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Yes, all you need to do in your “Save” button is to Call EndEdit on the CurrentCell and then save :

    If TypeOf GridControl1.CurrentCell Is Xceed.Grid.DataCell Then

    CType(GridControl1.CurrentRow, Xceed.Grid.DataRow).EndEdit()

    OleDbDataAdapter1.Update(DataSet11)

    DataSet11.AcceptChanges()

    Thats it ! 🙂

    Imported from legacy forums. Posted by Matt (had 488 views)

    User (Old forums)
    Member
    Post count: 23064

    No, that didn’t work. When the system tries to resolve the line

    If TypeOf gcPrimary.CurrentCell Is Xceed.Grid.DataCell Then

    it comes back as false and therefore doesn’t process the rest of the code. If I bypass that line and try to run the code anyway, I get:

    Specified Cast is not valid (InvalidCastException)

    from the line

    CType(gcPrimary.CurrentRow, Xceed.Grid.DataRow).EndEdit()

    Imported from legacy forums. Posted by DimondWoof (had 420 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Oups, strange I did test this before I replied to the thread. I will take a look at this and get back to you shortly.

    Imported from legacy forums. Posted by Matt (had 700 views)

    User (Old forums)
    Member
    Post count: 23064

    I double checked and everything works fine on my end. It is normal that you get an InvalidCastException in the case where you are trying to cast to an invalid type. Is it possible that you are on a row other than a DataRow when you press on the Save button to commit your changes?

    I will send you the sample application that I am using via email.

    Imported from legacy forums. Posted by Matt (had 514 views)

    User (Old forums)
    Member
    Post count: 23064

    I enter the grid, the 3rd column is the only one that is not read-only. I type text into that column and then I click on the save button. I do no other steps between those. This happens with a NEW row in the grid but not while editing an existing row in the grid.

    How do I save a NEW row?

    Imported from legacy forums. Posted by DimondWoof (had 439 views)

    User (Old forums)
    Member
    Post count: 23064

    Here is what I do.

    if (InsertionRow.IsBeingEdited)
    {
    InsertionRow.EndEdit();
    }

    I do the same for all the datarows. Only one row can be edited at a time, so break after you find the first row being edited.

    foreach(DataRow dRow in myGrid)
    {
    if (dRow.IsBeingEdited)
    {
    dRow.EndEdit();
    break;
    }
    }

    I know this is C#, but you get the picture.

    Imported from legacy forums. Posted by MBonafe (had 486 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you VERY much. Believe it or not, this is what I derived out of your C# example for VB:

    If CType(gcPrimary.CurrentRow, Xceed.Grid.InsertionRow).IsBeingEdited Then
    CType(gcPrimary.CurrentRow, Xceed.Grid.InsertionRow).EndEdit()
    End If

    But it works great. The only thing I had to do is check for an InvalidCastException for when the user tries to save with nothing in the row. I could probably test for it somehow, but This was the easy way to deal with it.

    Imported from legacy forums. Posted by DimondWoof (had 494 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks to all involved in this thread. I am trying to implement the same fix on my first grid.

    I am new to VB.Net and Xceed. The grid is the keystone of my entire app. I really like the product because is is fast and very very robust. As a newbie I am really having to struggle (ask Pierre-Luc) with the basics.

    Here is my basic philosophical question:

    Why doesn’t the XCeed documentation include a functional “Grid For Dummies” section that walks neophites through the things we all want, like Fill a grid, add a new row, initialize the cells where the values are predictable, let the user edit it, Save it, Delete it?

    I am about to get there after a monumental 2 week struggle, but I was hoping it would be a lot more clearly documented.

    Imported from legacy forums. Posted by Clay Rankin (had 670 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Clay,

    Thank you for you comments ! Indeed we will retouch our helpfile and make it more user-friendly as possible. However, It is always a pleasure to help you real time on the phone :).

    Cheers (h)

    Imported from legacy forums. Posted by Matt (had 357 views)

    User (Old forums)
    Member
    Post count: 23064

    Here’s the same thing in VB, which worked for me.

    For Each row As Xceed.Grid.DataRow In gcAccountDetail.DataRows
    If row.IsBeingEdited Then
    row.EndEdit()
    End If
    Next

    Imported from legacy forums. Posted by Dwight (had 8913 views)

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.