Results 1 to 8 of 8

Thread: Use checkboxs in datagridview cells to change value

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    78

    Use checkboxs in datagridview cells to change value

    Hi, I am trying to create a form that will update a database of school tests with checkboxs.
    Basically, i have a textbox for a student id, a combobox with the subjects in it, and a datagridview with the tests of the selected subject.(There are about ten subects with about ten tests each).
    What i want to happen is when you put in an id number, it should bring up all the tests the student passed in each subject in the datagridview. So when you select a subject it will load the datagridview with the tests (in a checkbox format) (with the tests he already passed checked) so you can click and add tests and then save it to the db.
    I hope you understand what i am trying to accomplish, bec. i am a noob trying to learn new things.
    Thanks for any help!

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Use checkboxs in datagridview cells to change value

    The attached VS2008 project provides you with the resources needed to handle CheckBox columns so that you can pick out what you need.

    Run the project, select one or more items in the top DataGridView then press the Process button which transfers the checked rows to the bottom DataGridView. The process operation would be where you get the logic to know which subjects where selected and instead of transfering them to another DataGridView do what you want with them.

    Also there is logic to allow the user to click one check box to select all row or deselect all rows and finally remember which ones where checked in the upper DataGridView next time the demo is executed as it stores this information within an XML sessions file.

    As mentioned above this provides the code to grab and adapt to your project and does not do it for you.
    Attached Files Attached Files

  3. #3
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Use checkboxs in datagridview cells to change value

    What code do you have now?
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    78

    Re: Use checkboxs in datagridview cells to change value

    Is it possible to give me the example using an access database (sorry for not stating that before), because thats what i'm using for the rest of my app.
    Thanks!

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Use checkboxs in datagridview cells to change value

    Quote Originally Posted by vbginner View Post
    Is it possible to give me the example using an access database (sorry for not stating that before), because thats what i'm using for the rest of my app.
    Thanks!
    In regards to an example with MS-Access, use an OleDb connection, OleDb command then use a reader to load a DataTable which is how you get to the point I work into the DataGridView

    Basic outline
    Code:
    Dim dt As New DataTable
    Dim cn As New OleDbConnection("Your MS-Access connection string")
    Dim cmd As OleDbCommand = New OleDbCommand
    cmd.Connection = cn
    cmd.CommandText = "Your SQL Statement"
    cn.Open()
    dt.Load(cmd.ExecuteReader())
    Then back to my example

    Adjust columns to match your fields from the SQL statement
    Code:
    DataGridView1.Columns.AddRange( . . .
    Assign BindingSource data source as shown below
    Code:
    mCustomersBindingSource.DataSource = Dt.DefaultView

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    78

    Re: Use checkboxs in datagridview cells to change value

    Is it possible to get it to save in my access db in a column called "tests" in the row of the id number provided in the textbox?
    can i make it that when you click the checkbox for test #1 it will add test1 to the db, and test #2 and so on... in the same column, maybe separated with commas, and then the program will be able to read it?
    Thanks alot! your help is greatly appreciated!

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Use checkboxs in datagridview cells to change value

    Quote Originally Posted by vbginner View Post
    Is it possible to get it to save in my access db in a column called "tests" in the row of the id number provided in the textbox?
    can i make it that when you click the checkbox for test #1 it will add test1 to the db, and test #2 and so on... in the same column, maybe separated with commas, and then the program will be able to read it?
    Thanks alot! your help is greatly appreciated!
    Yes you can, as with the read from XML then I changed it to reading from a database so can you write to a database table using SQL statements to see if a specific row exists, if not create it and insert your data or if the row does exists update the values. Then when you need to read them back use a SELECT WHERE statement.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    78

    Re: Use checkboxs in datagridview cells to change value

    will i be able to separate each test after, to make a print out of the tests passed categorized by subject?
    And btw,how does this work? :
    "In regards to an example with MS-Access, use an OleDb connection, OleDb command then use a reader to load a DataTable which is how you get to the point I work into the DataGridView

    Basic outline
    Code:
    Dim dt As New DataTable
    Dim cn As New OleDbConnection("Your MS-Access connection string")
    Dim cmd As OleDbCommand = New OleDbCommand
    cmd.Connection = cn
    cmd.CommandText = "Your SQL Statement"
    cn.Open()
    dt.Load(cmd.ExecuteReader())
    Then back to my example

    Adjust columns to match your fields from the SQL statement

    Code:
    DataGridView1.Columns.AddRange( . . .
    Assign BindingSource data source as shown below

    Code:
    mCustomersBindingSource.DataSource = Dt.DefaultView
    "
    Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width