|
-
Jan 11th, 2011, 03:13 PM
#1
Thread Starter
Lively Member
CONNECT RadioButton TO DATABASE
Hi,
i have a form with a bunch of textbox's that are connected to a ms access data source, so i can update, edit and delete records.
I also have 4 radio buttons.
What i'm trying to acheive is that when a row is selected in the datagridview, the textboxes show the values in them (id, name, number, etc.),which works perfectly, and the radio buttons should show the value of the "grade" column of the cell that is selected.
So basicaly when you click a record, if the grade is 5 i want the radiobutton5 to be selected. And if i click radiobutton6 it should update the field to 6.
I hope i am being clear enough for you to understand me.
Thanks in advance!
-
Jan 11th, 2011, 03:22 PM
#2
Re: CONNECT RadioButton TO DATABASE
You will need to evaluate the value of the "grade" field and set checked property of the appropriate radio button manually.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 11th, 2011, 03:51 PM
#3
Thread Starter
Lively Member
Re: CONNECT RadioButton TO DATABASE
thanks for replying,
can you please explain further to what you mean (maybe with an example) because i'm a noob.
Thanks!
-
Jan 11th, 2011, 04:16 PM
#4
Re: CONNECT RadioButton TO DATABASE
Something like this:
Code:
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
Dim RBs() As RadioButton = {Me.RadioButton1, Me.RadioButton2, Me.RadioButton3, Me.RadioButton4, Me.RadioButton5, Me.RadioButton6}
Dim grade As Integer = CInt(Me.DataGridView1.CurrentRow.Cells("Grade").Value)
If grade > 0 AndAlso grade <= RBs.Length Then
RBs(grade - 1).Checked = True
End If
End Sub
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 11th, 2011, 08:50 PM
#5
Thread Starter
Lively Member
Re: CONNECT RadioButton TO DATABASE
Thanks for the reply!
I tried sticking that into my code and it doesnt check any radio button. I also noticed that i get this error when i try to add a new record: "Conversion from type 'DBNull' to type 'String' is not valid."
This is how i entered the code:
Code:
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Datalist.SelectionChanged
Dim RBs() As RadioButton = {Me.RadioButton4, Me.RadioButton5, Me.RadioButton6, Me.RadioButton7}
Dim grade As Integer = CInt (Me.Datalist.CurrentRow.Cells(5).Value)
If grade > 0 AndAlso grade <= RBs.Length Then
RBs(grade - 1).Checked = True
End If
End Sub
Thanks again for your help!
Last edited by vbginner; Jan 11th, 2011 at 08:52 PM.
Reason: mistake
-
Jan 12th, 2011, 11:57 AM
#6
Re: CONNECT RadioButton TO DATABASE
What are all the possible grades? Are they 4, 5, 6 and 7?
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 12th, 2011, 02:30 PM
#7
Thread Starter
Lively Member
Re: CONNECT RadioButton TO DATABASE
-
Jan 12th, 2011, 03:07 PM
#8
Re: CONNECT RadioButton TO DATABASE
Then try this:
Code:
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Datalist.SelectionChanged
Dim RBs() As RadioButton = {Me.RadioButton4, Me.RadioButton5, Me.RadioButton6, Me.RadioButton7}
Dim value as Object = Me.Datalist.CurrentRow.Cells(5).Value
Dim grade As Integer = 0
If value IsNot Nothing AndAlso Not IsDBNull(value) Then
grade = Cint(value)
Dim index As Integer = grade - 4
If index >= 0 AndAlso index < RBs.Length Then
RBs(index).Checked = True
End If
End If
End Sub
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jan 12th, 2011, 03:14 PM
#9
Thread Starter
Lively Member
Re: CONNECT RadioButton TO DATABASE
I GET AN ERROR AT
Code:
grade = CInt(value)
"Conversion from string "HJ" to type 'Integer' is not valid." (WHICH IS THE VALUE OF COLUMN 2)
THANKS!
Last edited by vbginner; Jan 12th, 2011 at 03:26 PM.
-
Jan 12th, 2011, 03:25 PM
#10
Thread Starter
Lively Member
Re: CONNECT RadioButton TO DATABASE
I just added some more records to the database, and realized that the code is getting the value of column #2 (which is a data column) instead of column #5.
How can i change that?
Thanks!
-
Jan 13th, 2011, 02:01 AM
#11
Thread Starter
Lively Member
Re: CONNECT RadioButton TO DATABASE
FIGURED IT OUT!
Dim value As Object = Me.Datalist.CurrentRow.Cells("GRADEDataGridViewTextBoxColumn").Value
THANKS ALOT!
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|