Solved

Checkbox cancel in unbound datagridview control

Posted on 2006-11-08
8
1,255 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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