Solved

Checkbox cancel in unbound datagridview control

Posted on 2006-11-08
8
1,243 Views
Last Modified: 2012-08-13
I have an unbound checkbox in a datagridview control. In the CellContentClick handler there is error checking that enables the user to cancel the event if the checkbox is checked. If the user selects Cancel I then set the value of the checkbox back to True then do a datagridview.refresh() and an Application.DoEvents thinking that should force the control to be redrawn with the checkbox checked but no such luck. Any ideas how this could be done?
0
Comment
Question by:tmostad
  • 5
  • 3
8 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17900225
what happens if you use the DataGridView.Refresh() method, does it redraw?
0
 
LVL 1

Author Comment

by:tmostad
ID: 17900651
No it has no effect. If I leave the form and return it is shown checked as it should be.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17900691
try Form.Refresh then?
0
 
LVL 1

Author Comment

by:tmostad
ID: 17901269
Nope, still no effect.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 13

Expert Comment

by:newyuppie
ID: 17901634
cant you post part of the code?
0
 
LVL 1

Author Comment

by:tmostad
ID: 17901735
Dim Response As DialogResult = MsgBox("Automatically generated values are being deleted. Are you sure you want to do this?",  MsgBoxStyle.Exclamation + MsgBoxStyle.OkCancel)

If Response = System.Windows.Forms.DialogResult.Cancel Then
    Me.DGV(e.ColumnIndex, e.RowIndex).Value = True
    Me.DGV.Refresh()
    Application.DoEvents()
    Exit Sub
End If
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17904127
from the MSDN documentation on CellContentClick event of the datagridview

Remarks
This event occurs when the cell content is clicked. It also occurs when the user presses and releases the SPACEBAR while a button cell or check box cell has focus, and will occur twice for these cell types if the cell content is clicked while pressing the SPACEBAR.

Use this event to detect button clicks for a DataGridViewButtonCell or link clicks for a DataGridViewLinkCell.

**IMPORTANT PART ** MY HIGHLIGHT
For clicks in a DataGridViewCheckBoxCell, this event occurs before the check box changes value, so if you do not want to calculate the expected value based on the current value, you will typically handle the DataGridView.CellValueChanged event instead. Because that event occurs only when the user-specified value is committed, which typically occurs when focus leaves the cell, you must also handle the DataGridView.CurrentCellDirtyStateChanged event. In that handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.
**

--
apparently the checkboxes change value AFTER CellContentClick consumed. try calling the DataGridView.CommitEdit in the CurrentCellDirtyStateChanged event as the article suggests.
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17904133
and use the CellValueChanged event rather than CellContentClick event...
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now