Solved

Checkbox in VB.NET Datagrid

Posted on 2004-08-24
7
646 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
[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
  • 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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