Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / February 2006

Tip: Looking for answers? Try searching our database.

Problem:  Invalid values returned from a checkbox column

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stockbuildingsupply - 21 Feb 2006 14:50 GMT
i have a bound dataviewgrid with a checkboxcolumn.  when the user clicks a
checkbox if the value is true i want a button to be enabled.  the logic is:
1-loop through checkboxcolumn cells
2-if the cell value is true enable the button and exit loop
3-if there were no checked cells disable the button
the problem is that the value returned by the checkbox cell is always false.
here is my code thus far:

 Private Sub oGrid_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles oGrid.Click
   Dim oGrd As DataGridView
   Dim bEnabled As Boolean = False
   If sender.GetType.IsInstanceOfType(New DataGridView) Then
     oGrd = sender
     If oGrd.CurrentCell.GetType.IsInstanceOfType(New
DataGridViewCheckBoxCell) Then
       For Each oRow As DataGridViewRow In oGrd.Rows
         If oRow.Cells("APPROVEDDataGridViewCheckBoxColumn").Value = True
Then
           bEnabled = True
           Exit For
         End If
       Next oRow
       btnOk.Enabled = bEnabled
     End If
   End If
 End Sub
Bart Mermuys - 21 Feb 2006 18:41 GMT
Hi,

>i have a bound dataviewgrid with a checkboxcolumn.  when the user clicks a
> checkbox if the value is true i want a button to be enabled.  the logic
[quoted text clipped - 4 lines]
> the problem is that the value returned by the checkbox cell is always
> false.

Are you saying that DGVCheckBoxCell.Value always returns false, or do you
mean that only the editing cell doesn't return the right value, there's a
difference.

To handle editing cells, you better handle DataGridView.CellContentClick and
check DGVCheckBoxCell.EditingCellFormattedValue.

If you are starting out with a complete unchecked grid, you could use the
above event and increase/decrease a counter so you don't need to loop all
rows.

HTH,
Greetings

> here is my code thus far:
>
[quoted text clipped - 17 lines]
>    End If
>  End Sub
stockbuildingsupply - 21 Feb 2006 20:57 GMT
Thanks Bart,
The EditingCellFormattedValue did what I needed.  In addition I took your
suggestion and implemented a counter to keep track instead of having to
iterate each time.

> Hi,
>
[quoted text clipped - 42 lines]
> >    End If
> >  End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.