How to clear a combo box .net 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am trying to clear a combo box at runtime. I am using the remove method,
and then I use the refresh method in order for the combo box to display
properly. But it does not work. I seemed to be missing something. Can anyone
help? I have been away from this for a while.
In C#:

iCnt = cbo.Items.Count;
while (cbo.Items.Count >0)
{
cbo.Items.Remove(iCnt); \\it removes it, but it does not reset the count
property
cbo.Refresh();
iCnt--;
}
 
Hi Lamborghini,

For removing combobox items you are using remove function
but it requires object i.e the entry, not the index of that entry. Suppose
if you have 3 items a, b and c then to remove "a", you can do
cbo.Items.Remove("a");

If you like to work on indexes the user RemoveAt function
cbo.Items.RemoveAt(iCnt - 1);

Regards,
Swapnil
 
Lamborghini,

Why don't you use the items collection Clear method

cbo.Items.Clear();
 
Thank you.
Lamborghini.


Swapnil Karoo said:
Hi Lamborghini,

For removing combobox items you are using remove function
but it requires object i.e the entry, not the index of that entry. Suppose
if you have 3 items a, b and c then to remove "a", you can do
cbo.Items.Remove("a");

If you like to work on indexes the user RemoveAt function
cbo.Items.RemoveAt(iCnt - 1);

Regards,
Swapnil
 
Back
Top