Bound ComboBox SelectedIndex Defaults to 0 
Author Message
 Bound ComboBox SelectedIndex Defaults to 0

Is it a bug?

In Windows Forms:

I have a combox on a form which is populated by a lookup table.

Below the combo i have VCR buttons to navigate thru the records of parent
table.

combo1.valuemember = "id"
combo1.displaymember = "desc"

Now when, the selectedvalue of the combo is changed to null, i am trying to
set
combo1.selectedindex = -1 but it defaults to 0.

I am not sure why it is happenning. I have no other databindings on that
combobox.



Mon, 27 Dec 2004 01:49:40 GMT  
 Bound ComboBox SelectedIndex Defaults to 0
Found a workaround for this. You need to add both the lines

to the code to make it work.

combobox1.SelectedItem = Nothing

combobox1.SelectedIndex = -1

Can someone explain if there is a right way to do this.


Quote:
> Is it a bug?

> In Windows Forms:

> I have a combox on a form which is populated by a lookup table.

> Below the combo i have VCR buttons to navigate thru the records of parent
> table.

> combo1.valuemember = "id"
> combo1.displaymember = "desc"

> Now when, the selectedvalue of the combo is changed to null, i am trying
to
> set
> combo1.selectedindex = -1 but it defaults to 0.

> I am not sure why it is happenning. I have no other databindings on that
> combobox.



Mon, 27 Dec 2004 02:11:46 GMT  
 Bound ComboBox SelectedIndex Defaults to 0
SelectedIndex cannot be set to a negative value. However, you can clear the
selection by setting SelectedItem to Nothing, which will set SelectedIndex
to -1

Thanks
Robin, Seth & Mohan
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> Is it a bug?

> In Windows Forms:

> I have a combox on a form which is populated by a lookup table.

> Below the combo i have VCR buttons to navigate thru the records of parent
> table.

> combo1.valuemember = "id"
> combo1.displaymember = "desc"

> Now when, the selectedvalue of the combo is changed to null, i am trying
to
> set
> combo1.selectedindex = -1 but it defaults to 0.

> I am not sure why it is happenning. I have no other databindings on that
> combobox.



Mon, 27 Dec 2004 04:25:55 GMT  
 Bound ComboBox SelectedIndex Defaults to 0
I am having the same problem, and setting SelectedItem to nothing does
nothing.

The following code is in a form_load sub. I want to populate a listbox
with the contents of a single-column SELECT. I read the data into an
arraylist and use this as the DataSource of the ListBox.

      Dim ListItems As New ArrayList()

      drdList = cmdList.ExecuteReader
      Do While drdList.Read
         ListItems.Add(CType(drdList.Item("Country"), String))
      Loop

      'Assign contents of Array to ListBox
      With lstCountries
         .SelectedItem = Nothing
        'If I single step and wait before following statement
        ' is executed, the next single-step takes the jumps
        ' into the ListBox_SelectedItemChanged event
         .DataSource = ListItems
         .DisplayMember = "Country"
      End With

This behavior is not what I expected. Should it be occuring?

Thanks - Larry

On Wed, 10 Jul 2002 13:25:55 -0700, "VBDotNet Team [MS]"

Quote:

>SelectedIndex cannot be set to a negative value. However, you can clear the
>selection by setting SelectedItem to Nothing, which will set SelectedIndex
>to -1

>Thanks
>Robin, Seth & Mohan
>VB Team



Mon, 03 Jan 2005 05:39:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Bound ComboBox SelectedIndex Defaults to 0

2. SelectedIndex not corresponding with .text in ComboBox

3. ComboBox.SelectedIndex = Nothing problem...

4. Combobox click/selectedindex problems

5. combobox selectedindex

6. Synchronizing bound combobox and bound textboxes?

7. Referencing a combobox value and the concept of the bound column

8. Partialy bound ComboBox?

9. Multi-Column Data-Bound ComboBox

10. Binding Combobox to SQLServer

11. Multi column Bind ComboBox ??

12. Listbox/Combobox binding problem

 

 
Powered by phpBB® Forum Software