Solved

Checkbox in VB.NET Datagrid

Posted on 2004-08-24
7
617 Views
Last Modified: 2008-03-10
I am trying to use a checkbox in a datagrid on a winform.  The specs are as follows:

Populating from XML file
Value in field that I am using is "True" or "False" (initially false)

I can get that column to display using the code listed below, however I am encountering several issues:

1) does not appear to be truly bound (though the description field populates correctly)
2) unable to edit the field
3) unrelated though bothersome, evidenceID field does not show up though it is populated in the XML file

--------------XML------------------------
- <Evidence>
- <EvidenceItem>
  <EvidenceID>456-1B</EvidenceID>
  <EvidenceType>Ballistic Evidence</EvidenceType>
  <Description>456</Description>
  <Location>56</Location>
  <Lab>False</Lab>
  </EvidenceItem>
  </Evidence>

---------------CODE-----------------------

               ds.Clear()
                ds.ReadXml(Application.StartupPath & "\CSUXml.xml")
                dgLabEvidence.DataSource = ds
                'dgLabEvidence.DataBindings(DataSource) = ds
                dgLabEvidence.DataMember = "EvidenceItem"

                ' Create the table format for the datagrid on the Evidence Submission form
                ts1.MappingName = "EvidenceItem"
                txtLabInvOff.Text = detectiveName

                Dim sampCol = New DataGridTextBoxColumn
                sampCol.MappingName = "EvidenceID"
                sampCol.HeaderText = "Sample ID"
                sampCol.Width = 70
                'If ts1(sampCol) = Nothing Then
                ts1.GridColumnStyles.Add(sampCol)
                'End If

                Dim descCol = New DataGridTextBoxColumn
                sampCol.MappingName = "Description"
                sampCol.HeaderText = "Description"
                sampCol.Width = 150
                'If ts1(descCol) = Nothing Then
                ts1.GridColumnStyles.Add(descCol)
                'End If

                'boolCol.DataBindings.Add(New Binding("Boolean", ds, "EvidenceID.Lab"))
                boolCol.MappingName = "Lab"
                boolCol.HeaderText = "Request Lab Exam?"
                boolCol.Width = 70
                boolCol.AllowNull = False
                'If ts1(boolCol)  Nothing Then
                ts1.GridColumnStyles.Add(boolCol)
                'End If

                dgLabEvidence.TableStyles.Add(ts1)
0
Comment
Question by:BodeTech
  • 4
7 Comments
 

Author Comment

by:BodeTech
Comment Utility
Problem 3 was a stupid error...in my definition of descCol I had copied my def from sampCol and forgot to chagne several lines to descCol...doh!
0
 

Author Comment

by:BodeTech
Comment Utility
One other problem...I have this code tied to a click on tab event on a form...if I leave that tab and come back I get an error because the columns have already been added.  However, If I try to use the checks (if statement that is commented) that generates its own error because it ("No default member found for the datagridcolumnstyle")

Help?  I need to only add the columns if they have not been added.
0
 
LVL 8

Expert Comment

by:gregasm
Comment Utility
shouldnt the code that checks for null / nothing read

'If ts1(descCol) is Nothing Then
                ts1.GridColumnStyles.Add(descCol)
                'End If

U were previously using

'If ts1(descCol) = Nothing Then
                ts1.GridColumnStyles.Add(descCol)
                'End If

IS not = operator to compare null values in vb
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:BodeTech
Comment Utility
Ok...so gregasm provided some level of hintage...he was correct that I needed to change the = to is...however the code should be

If ts1.GridColumnStyles.Item("EvidenceID") Is Nothing Then

Referenceing the GridColumnStyles.Item
then the MappingName string...rather than the DataGridTextBoxColumn variable name
0
 

Author Comment

by:BodeTech
Comment Utility
Actually this question has not been abandoned...but there has been no real answer yet either.  What gregasm provided was assistance on one afterthought element of the issue...there is much more involved.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
Comment Utility
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now