Solved

How do I set the value of a bound checkbox to False?

Posted on 2007-12-04
5
205 Views
Last Modified: 2013-12-25
I have an order form in my ADO.Net app. On the form is a checkbox that I would like the CheckState to be set so its default value is "Fasle".  When the "ADd New" button is clicked, the checkbox has a highlighted green square in it. I would like this to be empty (False). I would like that value to automatically drop into the database when it is updated. I've tried:
Checkbox.CheckState = CheckState.Unchecked
I've also tried to set the default value in the databse column for "False" but this won't work either.
How do I set the value to be "False" ?

Thanks
0
Comment
Question by:grouchyfd
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:VBRocks
ID: 20403320
Is the DataGridView bound to a DataSource?  

For example, do you set the DataSource to a DataTable or DataView, like this:
    Me.DataGridView1.DataSource = table

If you do, then you can just add a new row to the underlying table, and set the value before you add it.
Demonstration:
        'Example creating a DataTable to use as the source:
        Dim table As New DataTable()
        table.Columns.Add("IsSelected")
        table.Columns("IsSelected").DataType = GetType(Boolean)
        table.Columns.Add("Item")

        table.Rows.Add(False, "Item 1")

        Me.DataGridView1.DataSource = table


        'Example adding the new row:
        Dim table As DataTable
        table = Me.DataGridView1.DataSource

        Dim row As DataRow = table.NewRow()

        'Set the column to the Checked property in your Checkbox
        row("IsSelected") = Me.CheckBox1.Checked
        row("Item") = "Item 2"

        table.Rows.Add(row)


0
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 20403346
If your DataGridView is not bound to a DataSource as demonstrated above, then just use the
following approach:

    Me.DataGridView1.Rows.Add(Me.CheckBox1.Checked, "Item 1")

0
 

Author Comment

by:grouchyfd
ID: 20403645
I have the controls on the form  in the "Details" mode, not the DataGridView so the CheckBox is box with a label on the form. I've use the code frmOrderForm.CheckBox.CheckState.Unchecked. When I put this in the intellisense tells me to enter it as CheckState. Unchecked but then this comes up a s error also.
0
 

Author Comment

by:grouchyfd
ID: 20403689
I've gone into the table designer and changed the default property of the checkbox to "False". Then I get a different error when I try to update the database.
0
 

Author Comment

by:grouchyfd
ID: 20404940
I finally solved the problem.
I went to my data source using the DataSource window, clicked on the dataset, then opened it by using the  "Edit DataSet with Designer". Clicked on the row of the cloumn I needed to change the default value of, which opened the Properties Window for this row and changed the "Default Value" to "False". Now every time a row is created for a new order, the default of "False" ( int 0) is automatically entered into the database cloumn.
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

896 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