Solved

Checkbox cancel in unbound datagridview control

Posted on 2006-11-08
8
1,251 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:tmostad
ID: 17901269
Nope, still no effect.
0
 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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