C# .NET - DataGridView RowDeleting/deleted? - Asked By james peckham on 31-Oct-06 03:49 PM

Data set loaded into datagrid view

**got this working**want to save to the database after each row is finished (which event?)

**Got this part working for new and modified rows**want to prompt use for all changes prior to saving, reject if not (already written, just need the event to hook)

want to prompt use before deleting rows from the datagrid (different event than above as far as i can tell so far)

Should i just hook the dataset RowDeleting? is there a way to cancel the deletion at that point?



Row Deleting. - Jerry Laudat replied to james peckham on 31-Oct-06 05:52 PM

Here's a paste of my notes.
(A) The RowChangedEvent fires after a datarow has updated successfullly.  It has a Row property and an Action proeperrty.
  (B) The RowDeletingEvent occurs when a DAtaRow is inprocess of being deleted. Also has a Row property and an Action property.
   (C) The RowDeleted event is raised after a row witin a dataTAble is delted. Has Row and Action property.
 (D) ColumnChanging event fires before RowChanging.  Has the ProposedValue property which contains the new value that is the goal of the change.  The Column property refers to the column itself taken as an object where the change is occurring. The Row property (as DataRow object) enables you to retrieve the previous value at this Row,Column prior to this impending change of value.
  (E) The ColumhChanged event fire after new data is inserted or updated in a column. Also provides PropsoedValue, Column, and Row.

I've never tried it, but I should think you can cancel the edit, from within the handler sub:

 AddHandler d.RowChanging, AddressOf dataRow_RowChanging

Private Sub dataRow_RowChanging(ByVal s As Object, ByVal e As DataRowChangeEventArgs)
        e.Row.CancelEdit()
    End Sub




so you think hooking events on the dataset... - james peckham replied to Jerry Laudat on 31-Oct-06 11:15 PM

so you're saying the best way to handle edits within a datagridview (windows forms) is to handle events on the actual dataset? Will changes to the dataset immediately affect the datagridview or is there a way to manually update the binding source? I'll have to play around with it tomorrow at work, but what i had so far was actually checking to see if datarowstate was modified or added, then saving the row on bindingsource.positionchanged event... however users don't always change rows when they finish editing... also if you select a row and delete it... it doesn't fire position changed (strange because the position does change...)


I was hoping that the datagridview itself had events for deleting and adding... there is "OnCellParse" which only fires if the cell is modified... but i don't want to prompt the user for every single cell they edit :(

In the end, the users are wanting me to use the datagrid as a view and double click to open a record for editing anyhow, so i may just scrap the whole idea of editing through the DGV control.

Another question, if anyone knows... i noticed when i added a DataRow reference in my edit dialog form... it put it into the list of "EditDialogForm" list instances for binding options... is this automatic? and if so what triggers this? only enumerated instances? example, if i create a List<BusinessObject> reference in my form, will it show that as a possible binding source for controls?

I have no idea - Jerry Laudat replied to james peckham on 31-Oct-06 11:54 PM

Sorry, I haven't even used .Net 2.0 as yet.