I wrote some code to capture the user's selected values before changing them. Thus, allowing the changes to be restored to the previous values.
The problem I ran into was that my click event from the contextmenu is called multiple times. This wipes out the true previous values. I could just add a flag at the beginning of the event, but I was wondering if there was a better way to approach this? why is this click event called multiple times on a single click?
01.Private Sub FF_MenuItem_Click(sender As Object, e As EventArgs) Handles FF_MenuItem.Click02.'Populate selected cells with "FF"03.Try04.Dim cell As GridViewCellInfo05. 06.If dgvMain.SelectedCells.Count > 0 Then07._lastGridChange.Clear08.End If09. 10.For Each cell In dgvMain.SelectedCells11._lastGridChange.Add(cell.RowInfo.Index & "," & cell.ColumnInfo.Index & "," & cell.Value)12.cell.Value = "FF"13.Next14.Catch ex As Exception15.ShowErrorBox("No cell selection detected. Be sure to select a cell first.")16.End Try17.End SubLine 11. _lastGridChange saves the values before they are updated
01.Private Sub dgvMain_ContextMenuOpening(sender As Object, e As ContextMenuOpeningEventArgs) Handles dgvMain.ContextMenuOpening02. 03. FF_MenuItem.Text = "FF"04. HH_MenuItem.Text = "HH"05. CC_MenuItem.Text = "CC"06. ClearColumn_MenuItem.Text = "Clear Column Values"07. 08. Dim separator As RadMenuSeparatorItem = New RadMenuSeparatorItem()09. e.ContextMenu.Items.Add(separator)10. 11. Try12. e.ContextMenu.Items.Add(FF_MenuItem)13. e.ContextMenu.Items.Add(HH_MenuItem)14. e.ContextMenu.Items.Add(CC_MenuItem)15. e.ContextMenu.Items.Add(ClearColumn_MenuItem)16. Catch ex As Exception17. End Try18. 19. Try20. AddHandler FF_MenuItem.Click, AddressOf FF_MenuItem_Click21. AddHandler HH_MenuItem.Click, AddressOf HH_MenuItem_Click22. AddHandler CC_MenuItem.Click, AddressOf CC_MenuItem_Click23. AddHandler ClearColumn_MenuItem.Click, AddressOf ClearColumn_MenuItem_Click24. Catch ex As Exception25. End Try26.End SubSetting up the ContextMenu Options
