Problem Setting radio buttons based on data value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg

    #1

    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("tblP eramItems")
    Dim dr As DataRow = dt.Rows(0) 'first row in datatable

    If dr("strStockGro up") = "DVD" Then
    rdbDVD.Checked = True
    ElseIf dr("strStockGro up") = "Video" Then
    rdbVideo.Checke d = True
    ElseIf dr("strStockGro up") = "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
  • Steen Gellett

    #2
    Re: Problem Setting radio buttons based on data value

    "Greg" <gregrose@tpg.c om.au> skrev i en meddelelse
    news:c2a53ac8.0 405310338.2a28c 0e5@posting.goo gle.com...[color=blue]
    > 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("tblP eramItems")
    > Dim dr As DataRow = dt.Rows(0) 'first row in datatable
    >
    > If dr("strStockGro up") = "DVD" Then
    > rdbDVD.Checked = True
    > ElseIf dr("strStockGro up") = "Video" Then
    > rdbVideo.Checke d = True
    > ElseIf dr("strStockGro up") = "Computer Game" Then
    > rdbComputerGame .Checked = True
    > End If[/color]

    A better way to make this is :

    Select Case LCase(dr("strSt ockGroup")) ' LCase makes it lowercase
    Case "dvd"
    rdbDVD.Checked = True
    Case "video"
    rdbVideo.Checke d = True
    Case "computer game"
    rdbComputerGame .Checked = True
    End Select
    [color=blue]
    >
    > 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[/color]


    Comment

    • The Grim Reaper

      #3
      Re: Problem Setting radio buttons based on data value

      Replace If dr("strStockGro up") = "DVD" Then
      with If dr("strStockGro up").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" <gregrose@tpg.c om.au> wrote in message
      news:c2a53ac8.0 405310338.2a28c 0e5@posting.goo gle.com...[color=blue]
      > 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("tblP eramItems")
      > Dim dr As DataRow = dt.Rows(0) 'first row in datatable
      >
      > If dr("strStockGro up") = "DVD" Then
      > rdbDVD.Checked = True
      > ElseIf dr("strStockGro up") = "Video" Then
      > rdbVideo.Checke d = True
      > ElseIf dr("strStockGro up") = "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[/color]


      Comment

      Working...