65.9K
CodeProject is changing. Read more.
Home

DataGridView CheckBoxes and Context Menu

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Apr 30, 2013

CPOL
viewsIcon

11911

Simple Checkbox State changed in time for right click

Introduction

I recently had problems getting a checkbox state updated in time for a right click menu. The check box state is not available when a cell is in edit mode. A quick solution was to get the cell out of edit mode before the menu click events. I used the .cellcontentclick event; when the cell clicked was the check box, I moved over one cell. This has the action of leaving the edit mode on the cell of the checkbox. The column of the checkbox is 0 in the example.

dclconst CbSel_col value(00)
BegSr DataGridView1_CellContentClick Access(*Private) Event(*this.DataGridView1.CellContentClick)
DclSrParm sender Type(*Object)
DclSrParm e Type(System.Windows.Forms.DataGridViewCellEventArgs)
if e.ColumnIndex = CbSel_col
   DataGridView1.CurrentCell = DataGridView1(1+e.ColumnIndex,e.RowIndex) 
endif
EndSr