Solved

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

Posted on 2007-12-04
5
208 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
[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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 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