Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checkbox cancel in unbound datagridview control

Posted on 2006-11-08
8
Medium Priority
?
1,265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 total points
ID: 17904133
and use the CellValueChanged event rather than CellContentClick event...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 …
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

722 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