Solved

Checkbox in VB.NET Datagrid

Posted on 2004-08-24
7
632 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
ID: 11882633
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
ID: 11882693
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
ID: 11883401
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:BodeTech
ID: 11884393
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
ID: 12100949
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
ID: 12142911
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

838 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