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!
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.
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!
Re: Use checkboxs in datagridview cells to change value
Originally Posted by vbginner
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
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!
Re: Use checkboxs in datagridview cells to change value
Originally Posted by vbginner
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.
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