Home All Groups Group Topic Archive Search About
Author
25 Apr 2006 8:17 PM
straydawg
Creating listbox for Role and initially populating with loop

        myDataTable = myDataSet.Tables(1)
        lbRole.Items.Clear()
        Dim dataRow_t As DataRow
        For Each dataRow_t In myDataTable.Rows
         lbRole.Items.Add(dataRow_t("Role_Desc"))
        Next dataRow_t
        lbRole.SelectedIndex = -1

Thought I would try using binding

        lbRole.Items.Clear()
        lbRole.DisplayMember = "role_desc"
        lbRole.ValueMember = "role_id"
        lbRole.DataSource = myDataSet.Tables(1)
        lbRole.SelectedIndex = -1

When I use looping method, I am able to set lbRole.SelectedIndex = -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...

Author
25 Apr 2006 8:35 PM
Kerry Moorman
Dawg,

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

     lbRole.SelectedIndex = -1
     lbRole.SelectedIndex = -1

Kerry Moorman


Show quoteHide quote
"strayd***@hotmail.com" wrote:

> Creating listbox for Role and initially populating with loop
>
>         myDataTable = myDataSet.Tables(1)
>         lbRole.Items.Clear()
>         Dim dataRow_t As DataRow
>         For Each dataRow_t In myDataTable.Rows
>          lbRole.Items.Add(dataRow_t("Role_Desc"))
>         Next dataRow_t
>         lbRole.SelectedIndex = -1
>
> Thought I would try using binding
>
>         lbRole.Items.Clear()
>         lbRole.DisplayMember = "role_desc"
>         lbRole.ValueMember = "role_id"
>         lbRole.DataSource = myDataSet.Tables(1)
>         lbRole.SelectedIndex = -1
>
> When I use looping method, I am able to set lbRole.SelectedIndex = -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...
>
>
Author
25 Apr 2006 8:46 PM
straydawg
Thanks Kerry...

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

D
Author
25 Apr 2006 9:04 PM
Mythran
<strayd***@hotmail.com> wrote in message
Show quoteHide quote
news:1145996259.082338.88460@i40g2000cwc.googlegroups.com...
> Creating listbox for Role and initially populating with loop
>
>        myDataTable = myDataSet.Tables(1)
>        lbRole.Items.Clear()
>        Dim dataRow_t As DataRow
>        For Each dataRow_t In myDataTable.Rows
>         lbRole.Items.Add(dataRow_t("Role_Desc"))
>        Next dataRow_t
>        lbRole.SelectedIndex = -1
>
> Thought I would try using binding
>
>        lbRole.Items.Clear()
>        lbRole.DisplayMember = "role_desc"
>        lbRole.ValueMember = "role_id"
>        lbRole.DataSource = myDataSet.Tables(1)
>        lbRole.SelectedIndex = -1
>
> When I use looping method, I am able to set lbRole.SelectedIndex = -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...
>

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
Author
26 Apr 2006 5:44 AM
Cor Ligthert [MVP]
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

<strayd***@hotmail.com> schreef in bericht
Show quoteHide quote
news:1145996259.082338.88460@i40g2000cwc.googlegroups.com...
> Creating listbox for Role and initially populating with loop
>
>        myDataTable = myDataSet.Tables(1)
>        lbRole.Items.Clear()
>        Dim dataRow_t As DataRow
>        For Each dataRow_t In myDataTable.Rows
>         lbRole.Items.Add(dataRow_t("Role_Desc"))
>        Next dataRow_t
>        lbRole.SelectedIndex = -1
>
> Thought I would try using binding
>
>        lbRole.Items.Clear()
>        lbRole.DisplayMember = "role_desc"
>        lbRole.ValueMember = "role_id"
>        lbRole.DataSource = myDataSet.Tables(1)
>        lbRole.SelectedIndex = -1
>
> When I use looping method, I am able to set lbRole.SelectedIndex = -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...
>