[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2007-12-04
5
Medium Priority
?
211 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 1500 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
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…
Suggested Courses

649 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