Home All Groups Group Topic Archive Search About

ComboBox.Items.Clear()

Author
3 Oct 2006 8:23 PM
samoore33
I am populating a ComboBox at run time. I insert the first value of
"Choose Value"

cboTaxValue.Item.Insert(0, "Choose Value")

Then I loop through the rest of the values to be added to the combobox.

My problem is that when I try to clear the ComboBox it clears the items
that were inserted into the ComboBox, but does not clear the item I
selected in the ComboBox... For Instance.

The ComboBox has three choices: "Choose Value", ".023", ".546". I
choose ".023" from the list. After I select it, I make the needed
changes and press the update button. At the end of the UpdateButton
Method, I have a line of code: cboTaxValue.Items.Clear(). This line
removes all of the items in the ComboBox except for the item I had
previously selected. I have also tried cboTaxValue.SelectedText =
String.Empty, that does not clear the item selected in the ComboBox
either.

Puzzled and confused I am.

I hope this was enough explanation, appreciate any help.

Scott Moore

Author
3 Oct 2006 8:30 PM
rowe_newsgroups
Use cboTaxValue.Text = String.Empty instead.

Thanks,

Seth Rowe

samoore33 wrote:
Show quoteHide quote
> I am populating a ComboBox at run time. I insert the first value of
> "Choose Value"
>
> cboTaxValue.Item.Insert(0, "Choose Value")
>
> Then I loop through the rest of the values to be added to the combobox.
>
> My problem is that when I try to clear the ComboBox it clears the items
> that were inserted into the ComboBox, but does not clear the item I
> selected in the ComboBox... For Instance.
>
> The ComboBox has three choices: "Choose Value", ".023", ".546". I
> choose ".023" from the list. After I select it, I make the needed
> changes and press the update button. At the end of the UpdateButton
> Method, I have a line of code: cboTaxValue.Items.Clear(). This line
> removes all of the items in the ComboBox except for the item I had
> previously selected. I have also tried cboTaxValue.SelectedText =
> String.Empty, that does not clear the item selected in the ComboBox
> either.
>
> Puzzled and confused I am.
>
> I hope this was enough explanation, appreciate any help.
>
> Scott Moore
Author
4 Oct 2006 2:28 AM
samoore33
Seth,

You rock, that worked.

Thanks a lot

Scott Moore

rowe_newsgroups wrote:
Show quoteHide quote
> Use cboTaxValue.Text = String.Empty instead.
>
> Thanks,
>
> Seth Rowe
>
> samoore33 wrote:
> > I am populating a ComboBox at run time. I insert the first value of
> > "Choose Value"
> >
> > cboTaxValue.Item.Insert(0, "Choose Value")
> >
> > Then I loop through the rest of the values to be added to the combobox.
> >
> > My problem is that when I try to clear the ComboBox it clears the items
> > that were inserted into the ComboBox, but does not clear the item I
> > selected in the ComboBox... For Instance.
> >
> > The ComboBox has three choices: "Choose Value", ".023", ".546". I
> > choose ".023" from the list. After I select it, I make the needed
> > changes and press the update button. At the end of the UpdateButton
> > Method, I have a line of code: cboTaxValue.Items.Clear(). This line
> > removes all of the items in the ComboBox except for the item I had
> > previously selected. I have also tried cboTaxValue.SelectedText =
> > String.Empty, that does not clear the item selected in the ComboBox
> > either.
> >
> > Puzzled and confused I am.
> >
> > I hope this was enough explanation, appreciate any help.
> >
> > Scott Moore
Author
4 Oct 2006 1:07 AM
Kelly Ethridge
You can use

cboTaxValue.SelectedIndex = -1
or
cboTaxValue.SelectedItem = Nothing

to unselect a selected item.

Kelly



samoore33 wrote:
Show quoteHide quote
> I am populating a ComboBox at run time. I insert the first value of
> "Choose Value"
>
> cboTaxValue.Item.Insert(0, "Choose Value")
>
> Then I loop through the rest of the values to be added to the combobox.
>
> My problem is that when I try to clear the ComboBox it clears the items
> that were inserted into the ComboBox, but does not clear the item I
> selected in the ComboBox... For Instance.
>
> The ComboBox has three choices: "Choose Value", ".023", ".546". I
> choose ".023" from the list. After I select it, I make the needed
> changes and press the update button. At the end of the UpdateButton
> Method, I have a line of code: cboTaxValue.Items.Clear(). This line
> removes all of the items in the ComboBox except for the item I had
> previously selected. I have also tried cboTaxValue.SelectedText =
> String.Empty, that does not clear the item selected in the ComboBox
> either.
>
> Puzzled and confused I am.
>
> I hope this was enough explanation, appreciate any help.
>
> Scott Moore
>