Home All Groups Group Topic Archive Search About

Silly combo box question

Author
6 May 2006 3:27 PM
Adam Honek
Hi,

I've looked over and over and in MSDN 2005 and just can't find what
is a really simple answer.

How do I select the first value in a combo box to be shown?
I tried the .selectedindex -1 but it doesn't work.

At the moment it populates fine but it just remains blank unless I
dropdown the list.

Thanks,
Adam

Author
6 May 2006 3:39 PM
Herfried K. Wagner [MVP]
"Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb:
> I've looked over and over and in MSDN 2005 and just can't find what
> is a really simple answer.
>
> How do I select the first value in a combo box to be shown?
> I tried the .selectedindex -1 but it doesn't work.
>
> At the moment it populates fine but it just remains blank unless I
> dropdown the list.

Set the 'SelectedIndex' property to 0.  Setting it to -1 causes no item to
be selected, which is indicated by the blank combobox.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
6 May 2006 4:02 PM
Cor Ligthert [MVP]
Misreaded your answer therefore I did it again.

Sorry

Cor

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:%23zqY6MScGHA.380@TK2MSFTNGP04.phx.gbl...
> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb:
>> I've looked over and over and in MSDN 2005 and just can't find what
>> is a really simple answer.
>>
>> How do I select the first value in a combo box to be shown?
>> I tried the .selectedindex -1 but it doesn't work.
>>
>> At the moment it populates fine but it just remains blank unless I
>> dropdown the list.
>
> Set the 'SelectedIndex' property to 0.  Setting it to -1 causes no item to
> be selected, which is indicated by the blank combobox.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
6 May 2006 4:01 PM
Cor Ligthert [MVP]
Adam,

The first is 0 as most things that are derived from classic VB.

If you want an empty box by not binded data than you can use -1.

I hope this helps,

Cor

Show quoteHide quote
"Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht
news:%23gSqZGScGHA.4892@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> I've looked over and over and in MSDN 2005 and just can't find what
> is a really simple answer.
>
> How do I select the first value in a combo box to be shown?
> I tried the .selectedindex -1 but it doesn't work.
>
> At the moment it populates fine but it just remains blank unless I
> dropdown the list.
>
> Thanks,
> Adam
>
Author
6 May 2006 5:23 PM
Adam Honek
Thanks guys, 0 it is and works like a charm.

Adam

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%237BakYScGHA.1208@TK2MSFTNGP04.phx.gbl...
> Adam,
>
> The first is 0 as most things that are derived from classic VB.
>
> If you want an empty box by not binded data than you can use -1.
>
> I hope this helps,
>
> Cor
>
> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht
> news:%23gSqZGScGHA.4892@TK2MSFTNGP02.phx.gbl...
>> Hi,
>>
>> I've looked over and over and in MSDN 2005 and just can't find what
>> is a really simple answer.
>>
>> How do I select the first value in a combo box to be shown?
>> I tried the .selectedindex -1 but it doesn't work.
>>
>> At the moment it populates fine but it just remains blank unless I
>> dropdown the list.
>>
>> Thanks,
>> Adam
>>
>
>
Author
8 May 2006 4:06 PM
Jim Wooley
> Adam,
>
> The first is 0 as most things that are derived from classic VB.
>
> If you want an empty box by not binded data than you can use -1.

Unless you are talking Dotnet 1.x and currently have a value selected. In
that case, you need to set it to -1 twice (or sometimes 3 times). Actually,
I think the implementation in 2.0 sets the selectedindex to 0 then -1 if
you try to set it to -1 when it is currently > 0, which effectively means
that unselecting a value will cause a value to be selected temporarily and
then unselected. This to me is more silly than the original question which
has already been answered.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx