I was recently helping a coworker on a gridview context menu delete function. His was in CellSelect mode and he didn’t want to change it.
We searched for and found that people were insisting on FullRowSelect. I played around and got this to work. It allows row(s) to be deleted in either modes.
I had an attached database function which I removed and left a comment. The trick is to get the row from the set of selected cells and keep the last row deleted
to avoid duplicate deletes.
BegSr DeleteMenu1_Click Access(*Private) Event(*this.Deletemenu1.Click)
DclSrParm sender *object
DclSrParm eventArgs System.EventArgs
DclFld Rowy *Integer4
DclFld Cellx *Integer4
DclFld Last_Rowy *Integer4
*this.Cursor = System.Windows.Forms.Cursors.WaitCursor
if DataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect |
System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
Last_Rowy = -1
Do FromVal(0) ToVal(DataGridView.SelectedCells.Count - 1) Index(Cellx) // Cell Index
Rowy = DataGridView.SelectedCells(Cellx).Rowindex // get row index
if Last_Rowy <> Rowy
Last_Rowy = Rowy
// do any physical database deletes if required here
DataGridView.Rows.RemoveAt(Rowy)
endif
enddo
endif
*this.Cursor = System.Windows.Forms.Cursors.Arrow
EndSr