I have a column in my DataGridView
which has the DataGridViewCheckBoxColumn
as column template. When user checks the checkbox, I need to uncheck it programmatically if it fails some conditions. I have done this, but this uncheck logic only takes effect after I change the focus from the cell manually. I tried changing the focus programmatically but didn't work. Is there any solution for this?
Asked
Active
Viewed 4,818 times
1

Sunil
- 175
- 2
- 15
-
1Need more info. Are you trying to do this with JS? Can you use Ajax? – McArthey Nov 07 '12 at 05:05
-
cant use ajax ..its a windows application.. – Sunil Nov 07 '12 at 05:06
-
Ah sorry missed the winforms tag. – McArthey Nov 07 '12 at 05:09
-
Have a look at this question http://stackoverflow.com/questions/932040/triggering-a-checkbox-value-changed-event-in-datagridview-c-net/5385706#5385706 – TyCobb Nov 07 '12 at 05:20
-
@McArthey no sorry needed dude..i added the tag after you asked me. – Sunil Nov 07 '12 at 05:37
3 Answers
2
I found the answer with little code changes. I used the cancel edit function of datagridview. For checkbox value change to be fired previously i was using this code inside CurrentCellDirtyStateChanged event.
CommitEdit(DataGridViewDataErrorContexts.Commit)
Now i changed it to.
CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
And called the
CancelEdit()
to roll back the changes.

Sunil
- 175
- 2
- 15
-
can I know where you are calling CancelEdit method..coz it is failing in my case. – Sujith H S Dec 03 '15 at 05:16
1
Just set value of your DataGridViewCell.Value
property to false
(or true
):
((DataGridViewCheckBoxCell)row.Cells[CheckBoxColumn.Index]).value = false;

Ria
- 10,237
- 3
- 33
- 60
-
no ria i had tried that but it will come effect only if I changed the focus from the cell – Sunil Nov 07 '12 at 05:34
1
Recently I had similar problem. Setting Cell Value on false or working with TrueValue and FalseValue (for DataGridViewCheckBoxCell) failed in my case.
Finally i manage to achieve what I wanted (unchecking if some condition fails) with simple DataGridView method:
dataGridView1.CancelEdit()
Hope it helps.

Sorad
- 11
- 1