Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C# Combo Boxes

7 views
Skip to first unread message

Martin Hazell

unread,
May 6, 2003, 10:09:17 AM5/6/03
to
I have several comboboxes that are bound to a
datasource. What is the easiest way of not displaying
the first record from the dataset in the combobox?
Thanks

Martin

Dave Quigley

unread,
May 6, 2003, 12:38:29 PM5/6/03
to
Well I have looked through the documentation and it doesent seem like there
is an easy way to do this. From what I can see there are 2 ways, Grab the
collection from the box remove the first element and return a new instance
of the box with this collection to initialize it. Or you could make a custom
combo box that takes the data set then removes the first element and binds
the data to it. Thats just 2 possible ways. I didnt see anything specific
for removing stuff froma combo box so If anyone else knows of a better way
please correct me.


"Martin Hazell" <please...@to.group> wrote in message
news:082f01c313d9$14d4d7b0$a401...@phx.gbl...

Martin Hazell

unread,
May 6, 2003, 12:57:05 PM5/6/03
to
Sorry, I didn't make myself clear enough. I am not
wanting to remove the first element, just not have it
automatically selected. Normally a combobox will display
the first element as the selected element, but I would
like it to be blank to force them to select one an item,
and not leave it blank.

Thanks for your help anyway.

Martin

>.
>

Dave Quigley

unread,
May 6, 2003, 2:26:07 PM5/6/03
to
you might want to do 1 of 2 things. Add a value in which isnt a valid
selection somehting like select or Choose One, and check for valid input or
you can try setting SelectedItem to null. Im not sure if the second thing
will work. There is also selectedIndex but I dont think that will work at
all. That is if you want to get which item in the box is selected. You can
also set selected items with it.

These are all properties. Again I dont know if these will work for sure but
its a palce to start.

"Martin Hazell" <please...@to.group> wrote in message

news:08e201c313f0$86088550$a501...@phx.gbl...

Jude Regy

unread,
May 6, 2003, 4:44:54 PM5/6/03
to
Try comboBox.SelectedIndex = -1;

"Dave Quigley" <mer...@countercultured.net> wrote in message
news:e1iy2z$EDHA...@TK2MSFTNGP11.phx.gbl...

Dave Quigley

unread,
May 6, 2003, 8:26:55 PM5/6/03
to
You cant do that. It will throw an exception. Or so says the documentation

"Jude Regy" <jr...@rogers.com> wrote in message
news:a9Vta.106263$w7k....@news04.bloor.is.net.cable.rogers.com...

Martin Hazell

unread,
May 7, 2003, 4:55:57 AM5/7/03
to
Thanks for your suggestions.

I have tried all of these to no avail. Unfortunatly, it
won't let me insert an item directly into the combo-box
because it is bound to a datasource. Also when setting
the selected index/item/value to 0, -1 or null, it
automatically moves to the next valid position - ie the
first item. I have also tried to set Text = "" on the
form load, but that doesn't work either.

Thanks for all your help
Martin

>.
>

HyperX

unread,
May 7, 2003, 10:23:45 AM5/7/03
to
Martin,

There seems to be a problem with the SelectedIndex.

What I do is execute the same code twice and it gets set to -1. The
value in the DB is going to be null when the SelectedIndex is -1.

myComboBox.SelectedIndex = -1;
myComboBox.SelectedIndex = -1;

Hope this helps.

HyperX.

0 new messages