Solved

Checkbox in VB.NET Datagrid

Posted on 2004-08-24
7
626 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web Form VB.Net  import CSV 4 36
Reading the Web.Config using IIS 7.5? 4 35
Search an image for an image 3 29
Example works but why do I need to click twice on button 4 36
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

774 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