469,167 Members | 1,196 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

Problem Setting radio buttons based on data value

I'm trying to set a group of radio buttons based on the value of a
text field in a dataset. This is my code:

Dim ds As DataSet
ds = dtsVideo
Dim dt As DataTable = ds.Tables("tblPeramItems")
Dim dr As DataRow = dt.Rows(0) 'first row in datatable

If dr("strStockGroup") = "DVD" Then
rdbDVD.Checked = True
ElseIf dr("strStockGroup") = "Video" Then
rdbVideo.Checked = True
ElseIf dr("strStockGroup") = "Computer Game" Then
rdbComputerGame.Checked = True
End If

This works as long as I have "Option Strict" set to "Off". Otherwise
i get the error "Option strict on disallows operands of type object
for operator '='.
Use the 'Is' operator to test for object Identity"

Unfortunately I am required to have "Option Strict" set to "ON". Any
ideas on how I can make this work?

Greg
Jul 17 '05 #1
2 3971
"Greg" <gr******@tpg.com.au> skrev i en meddelelse
news:c2**************************@posting.google.c om...
I'm trying to set a group of radio buttons based on the value of a
text field in a dataset. This is my code:

Dim ds As DataSet
ds = dtsVideo
Dim dt As DataTable = ds.Tables("tblPeramItems")
Dim dr As DataRow = dt.Rows(0) 'first row in datatable

If dr("strStockGroup") = "DVD" Then
rdbDVD.Checked = True
ElseIf dr("strStockGroup") = "Video" Then
rdbVideo.Checked = True
ElseIf dr("strStockGroup") = "Computer Game" Then
rdbComputerGame.Checked = True
End If
A better way to make this is :

Select Case LCase(dr("strStockGroup")) ' LCase makes it lowercase
Case "dvd"
rdbDVD.Checked = True
Case "video"
rdbVideo.Checked = True
Case "computer game"
rdbComputerGame.Checked = True
End Select

This works as long as I have "Option Strict" set to "Off". Otherwise
i get the error "Option strict on disallows operands of type object
for operator '='.
Use the 'Is' operator to test for object Identity"

Unfortunately I am required to have "Option Strict" set to "ON". Any
ideas on how I can make this work?

Greg

Jul 17 '05 #2
Replace If dr("strStockGroup") = "DVD" Then
with If dr("strStockGroup").ToString = "DVD" Then

Option Strict On requires all datatypes are consistent - so you must tell
..NET that the data from your row is a string.

As I've seen mentioned many many times in this group, your post should be
sent to .NET forums, not this VB6 forum.
__________________________________________
The Grim Reaper

"Greg" <gr******@tpg.com.au> wrote in message
news:c2**************************@posting.google.c om...
I'm trying to set a group of radio buttons based on the value of a
text field in a dataset. This is my code:

Dim ds As DataSet
ds = dtsVideo
Dim dt As DataTable = ds.Tables("tblPeramItems")
Dim dr As DataRow = dt.Rows(0) 'first row in datatable

If dr("strStockGroup") = "DVD" Then
rdbDVD.Checked = True
ElseIf dr("strStockGroup") = "Video" Then
rdbVideo.Checked = True
ElseIf dr("strStockGroup") = "Computer Game" Then
rdbComputerGame.Checked = True
End If

This works as long as I have "Option Strict" set to "Off". Otherwise
i get the error "Option strict on disallows operands of type object
for operator '='.
Use the 'Is' operator to test for object Identity"

Unfortunately I am required to have "Option Strict" set to "ON". Any
ideas on how I can make this work?

Greg

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Owen Funkhouser | last post: by
15 posts views Thread by JR | last post: by
4 posts views Thread by Oscar Monteiro | last post: by
3 posts views Thread by rob c | last post: by
1 post views Thread by IchBin | last post: by
4 posts views Thread by Blasting Cap | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.