Solved

Checkbox cancel in unbound datagridview control

Posted on 2006-11-08
8
1,261 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
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…

635 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