Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checkbox in VB.NET Datagrid

Posted on 2004-08-24
7
Medium Priority
?
659 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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