ListBox Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • straydawg@hotmail.com

    #1

    ListBox Control

    Creating listbox for Role and initially populating with loop

    myDataTable = myDataSet.Table s(1)
    lbRole.Items.Cl ear()
    Dim dataRow_t As DataRow
    For Each dataRow_t In myDataTable.Row s
    lbRole.Items.Ad d(dataRow_t("Ro le_Desc"))
    Next dataRow_t
    lbRole.Selected Index = -1

    Thought I would try using binding

    lbRole.Items.Cl ear()
    lbRole.DisplayM ember = "role_desc"
    lbRole.ValueMem ber = "role_id"
    lbRole.DataSour ce = myDataSet.Table s(1)
    lbRole.Selected Index = -1

    When I use looping method, I am able to set lbRole.Selected Index = -1
    so no value is selected for the listbox. When I try the same method for
    the binding, I still get a value selected.

    I would like to bind, but need to be able allow input with no role
    selected.

    Thanks in advance...

  • Kerry Moorman

    #2
    RE: ListBox Control

    Dawg,

    Does setting it twice have the desired effect? For example:

    lbRole.Selected Index = -1
    lbRole.Selected Index = -1

    Kerry Moorman


    "straydawg@hotm ail.com" wrote:
    [color=blue]
    > Creating listbox for Role and initially populating with loop
    >
    > myDataTable = myDataSet.Table s(1)
    > lbRole.Items.Cl ear()
    > Dim dataRow_t As DataRow
    > For Each dataRow_t In myDataTable.Row s
    > lbRole.Items.Ad d(dataRow_t("Ro le_Desc"))
    > Next dataRow_t
    > lbRole.Selected Index = -1
    >
    > Thought I would try using binding
    >
    > lbRole.Items.Cl ear()
    > lbRole.DisplayM ember = "role_desc"
    > lbRole.ValueMem ber = "role_id"
    > lbRole.DataSour ce = myDataSet.Table s(1)
    > lbRole.Selected Index = -1
    >
    > When I use looping method, I am able to set lbRole.Selected Index = -1
    > so no value is selected for the listbox. When I try the same method for
    > the binding, I still get a value selected.
    >
    > I would like to bind, but need to be able allow input with no role
    > selected.
    >
    > Thanks in advance...
    >
    >[/color]

    Comment

    • straydawg@hotmail.com

      #3
      Re: ListBox Control

      Thanks Kerry...

      Not really. I see the the value for the lbRole.Selected Index is -1, but
      when looking at the listbox on the form, there still is a value
      selected. ??

      D

      Comment

      • Mythran

        #4
        Re: ListBox Control


        <straydawg@hotm ail.com> wrote in message
        news:1145996259 .082338.88460@i 40g2000cwc.goog legroups.com...[color=blue]
        > Creating listbox for Role and initially populating with loop
        >
        > myDataTable = myDataSet.Table s(1)
        > lbRole.Items.Cl ear()
        > Dim dataRow_t As DataRow
        > For Each dataRow_t In myDataTable.Row s
        > lbRole.Items.Ad d(dataRow_t("Ro le_Desc"))
        > Next dataRow_t
        > lbRole.Selected Index = -1
        >
        > Thought I would try using binding
        >
        > lbRole.Items.Cl ear()
        > lbRole.DisplayM ember = "role_desc"
        > lbRole.ValueMem ber = "role_id"
        > lbRole.DataSour ce = myDataSet.Table s(1)
        > lbRole.Selected Index = -1
        >
        > When I use looping method, I am able to set lbRole.Selected Index = -1
        > so no value is selected for the listbox. When I try the same method for
        > the binding, I still get a value selected.
        >
        > I would like to bind, but need to be able allow input with no role
        > selected.
        >
        > Thanks in advance...
        >[/color]

        In ASP.Net, we would, after the data bind, add a new item to the list (empty
        item). Then you can set the SelectedValue/SelectedItem.

        HTH,
        Mythran

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: ListBox Control

          Sraydaw,

          Is it not a little bit strange that when you bind a box in the listbox. You
          want to bind one box to nothing, you can add an empty row in your datatable,
          but that gives your mostly more problems than results.

          Cor

          <straydawg@hotm ail.com> schreef in bericht
          news:1145996259 .082338.88460@i 40g2000cwc.goog legroups.com...[color=blue]
          > Creating listbox for Role and initially populating with loop
          >
          > myDataTable = myDataSet.Table s(1)
          > lbRole.Items.Cl ear()
          > Dim dataRow_t As DataRow
          > For Each dataRow_t In myDataTable.Row s
          > lbRole.Items.Ad d(dataRow_t("Ro le_Desc"))
          > Next dataRow_t
          > lbRole.Selected Index = -1
          >
          > Thought I would try using binding
          >
          > lbRole.Items.Cl ear()
          > lbRole.DisplayM ember = "role_desc"
          > lbRole.ValueMem ber = "role_id"
          > lbRole.DataSour ce = myDataSet.Table s(1)
          > lbRole.Selected Index = -1
          >
          > When I use looping method, I am able to set lbRole.Selected Index = -1
          > so no value is selected for the listbox. When I try the same method for
          > the binding, I still get a value selected.
          >
          > I would like to bind, but need to be able allow input with no role
          > selected.
          >
          > Thanks in advance...
          >[/color]


          Comment

          Working...