none
How to edit a row in a DataGridView

    Question

  • Normally I do web applications and this is why I'm lost.

    I have a winform that has a datagrid view which is bound to a BoundDataSource control who's source is a class that comes as part of a intra-department web service.  When I want to edit a row, I don't want to continually hit the web service for each cell as it's updated, I want to do something like:

    OnRowEnter()
    {
        gvData.CurrentRow.BeginEdit();
    }

    OnRowExit()
    {
        if(gvData.IsCurrentRowDirty)
        {
            //Save row to data store through web service
        }
        gvData.CurrentRow.EndEdit();
    }

    Unfortunately it doesn't appear to be so easy.  How would you accomplish this is a winform using DataGridView and BoundDataSource.  This updating on every cell stuff is for the birds...talk about wasted bandwidth, and this is what I'm currently having to do using the BoundDataSource_ListChanged event...so I'm sure there's something I'm doing wrong.


    Thanks.

    Friday, December 15, 2006 2:32 AM

Answers

  • Hi, bri189a

    The update is based on row, if you still editing on the same row and switch from cell to cell, it would not update the datasouce.

    Regards.

    Ye

    Friday, January 12, 2007 6:38 AM

All replies

  • Hi,

    If you are using the BindingSource object, this is the default behavior. You have nothing to do.

    Charles

    Friday, December 15, 2006 3:49 AM
  • The behavior I'm seeing is that when I enter a cell, edit, then exit, it wants to update the bound data source.  Then if I go to the next cell on that same row, edit, then exit, it updates the bound data source again.  This is resulting in me sending an update through the web service everytime a cell is edited because I'm tied into the BoundDataSource_ListChanged event.  If I edit 4 cells in the same row I call the web service 4 times, when really I should only be calling it once...when I've completed editing all cells for that row.  Because the 'edit' mode seems to be specific to a cell and not a row I'm not sure how to get around this.
    Friday, December 15, 2006 1:29 PM
  • Ah,

    Try using the RowEnter and RowLeave events.

    Charles

    Friday, December 15, 2006 8:26 PM
  • Hi, bri189a

    The update is based on row, if you still editing on the same row and switch from cell to cell, it would not update the datasouce.

    Regards.

    Ye

    Friday, January 12, 2007 6:38 AM