remove an item from a drop down list

  • Thread starter Thread starter Marina
  • Start date Start date
M

Marina

Hi,
if anyone can help me with this i would apreciate it.

I have 2 drop down lists, and between them, they have some values that
are similar. How can i fill the second drop down and remove the item
thats selected in the first drop down, so that the same item doesnt
appear on both drop downs?

i have tried doing this after i load both dropdowns:
2ndlist.Items.Remove(1stlist.SelectedItem.Text) BUT NOTHING HAPPENS. I
still get the value on both drop downs

it only works with the index:
2ndlist.Items.RemoveAT(1stlist.SelectedIndex) BUT its not right since
drop downs dont have the same amount of items.
 
Hi,
if anyone can help me with this i would apreciate it.

I have 2 drop down lists, and between them, they have some values that
are similar. How can i fill the second drop down and remove the item
thats selected in the first drop down, so that the same item doesnt
appear on both drop downs?

i have tried doing this after i load both dropdowns:
2ndlist.Items.Remove(1stlist.SelectedItem.Text) BUT NOTHING HAPPENS. I
still get the value on both drop downs

it only works with the index:
2ndlist.Items.RemoveAT(1stlist.SelectedIndex) BUT its not right since
drop downs dont have the same amount of items.

Marina

I think you will need to use the index, one of my apps does:

int intIndex = lstTasks.SelectedIndex;
if(intIndex > 0)
{
string strItem = lstTasks.Text;
lstTasks.Items.RemoveAt(intIndex);
lstTasks.Items.Insert(intIndex - 1, strItem);
lstTasks.SelectedIndex = intIndex - 1;
JWriteRunOrder();
}

This is for moving items in a ListBox but can be adapted to do
what you need.
 
Dim i As Integer = cmb1.SelectedInde
Dim s As String = System.Convert.ToString(cmb1.Items.Item(i)

For i = 0 To cmb2.Items.Count -
Dim sTmp As Strin
sTmp = System.Convert.ToString(cmb2.Items.Item(i)
If s = sTmp The
cmb2.Items.RemoveAt(i
Exit Fo
End I
Nex
 
Jeff Gaines said:
Marina

I think you will need to use the index, one of my apps does:

int intIndex = lstTasks.SelectedIndex;
if(intIndex > 0)
{
string strItem = lstTasks.Text;
lstTasks.Items.RemoveAt(intIndex);
lstTasks.Items.Insert(intIndex - 1, strItem);
lstTasks.SelectedIndex = intIndex - 1;
JWriteRunOrder();
}

This is for moving items in a ListBox but can be adapted to do
what you need.


The thing is that the drop downs are allready loaded with values and i
just need to remove from the 2nd drop down the value thats selected in
the 1st drop down. BUT since they dont have all the same values or
number of values the indexes on each value are different in each drop
down
 
The thing is that the drop downs are allready loaded with values and i
just need to remove from the 2nd drop down the value thats selected in
the 1st drop down. BUT since they dont have all the same values or
number of values the indexes on each value are different in each drop
down

Ok, Nevermind. Found the answer:
2ndlist.Items.Remove(1stlist.SelectedItem)

as simple as that. BUT (theres always a but) i need an IF statement to
make sure i dont get an exeption in case the selected item in the 1st
list doesnt exist also in the second list and can't be removed!
 
Back
Top