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

Why no SelectedIndex() function for DropDownLists?

2,410 views
Skip to first unread message

Brett Langston

unread,
Jun 26, 1998, 3:00:00 AM6/26/98
to

There is a serious shortcoming in the implementation of the DropDownList
object, namely the inability to find out the selected index. There is a
function in the ListBox object called SelectedIndex() which does this, but
not in DropDownListBox.

I thought that I might be able to monitor the CBN_SELCHANGE message myself
by adding the corresponding pbm_cbnselchange user event to my drop down
list, but it seems as though Sybase forgot to provide support for this
notification--the pbm_cbnselchange user event does not exist.

Am I overlooking something obvious? I don't think so... Some of my code
is quite impossible to implement if I can't get the currently selected
index from my drop down listboxes. This seems like a lack of basic
functionality, unless I am missing something... If somebody knows of a way
to catch the CBN_SELCHANGE event, or to ask the DropDownListbox what its
currently selected item is, I would love to hear about it.

- Brett

Lucius A. Powell

unread,
Jun 27, 1998, 3:00:00 AM6/27/98
to

The dropdown listbox selectionchanged event provides an integer argument
which is the selected index. You could trigger or post to your user defined
method, passing the index.


Brett Langston wrote in message <01bda155$8e27b160$fc0000c0@babbage>...


>There is a serious shortcoming in the implementation of the DropDownList
>object, namely the inability to find out the selected index. There is a
>function in the ListBox object called SelectedIndex() which does this, but
>not in DropDownListBox.

[snipped]

Sanjiv Das [TeamPS]

unread,
Jun 27, 1998, 3:00:00 AM6/27/98
to

Brett,

I don't use drop down list boxes, so I do not have a direct answer to your
question.

I am curious, though, about why you are not using DDDWs. Did you consider
them and discard them for some reason ? IMHO, DDDWs are much easier to
populate with data than DDLBs, and you have a lot more control over DDDWs
than DDLBs.


HTH

Sanjiv Das [TeamPS]

Brett Langston wrote in message <01bda155$8e27b160$fc0000c0@babbage>...
>There is a serious shortcoming in the implementation of the DropDownList
>object, namely the inability to find out the selected index. There is a
>function in the ListBox object called SelectedIndex() which does this, but
>not in DropDownListBox.
>

Simon

unread,
Jun 29, 1998, 3:00:00 AM6/29/98
to

Two solutions:
1. Write your own function. You can create your own standard DDLB base
object and add the function to that. You need to loop through all the items
and check for a match.
2. Use an external dw with a column type of DDDW instead.

I would recommend (2)

Simon

Brett Langston

unread,
Jun 29, 1998, 3:00:00 AM6/29/98
to

One big reason for not using DDDW's is portability. DDDW's are a very
specific feature of PowerBuilder, whereas drop-down listboxes are not. I
hope to port my code to a C++ or Java implementation soon, so DDDW's are
not a good option for me. I appreciate the advice though, and I will look
into using the DDDW's if this is the only way to get around this problem (I
didn't think of using them until you mentioned it, thanks). It still seems
strange, however, that drop-down listboxes are missing this very basic
capability.

- Brett Langston

Sanjiv Das [TeamPS] <eMail...@CompuServe.Com> wrote in article
<68wlh6e...@forums.powersoft.com>...
> ...I am curious, though, about why you are not using DDDWs. Did you
consider
> them and discard them for some reason ?...


>
>
> Brett Langston wrote in message <01bda155$8e27b160$fc0000c0@babbage>...
> >There is a serious shortcoming in the implementation of the DropDownList
> >object, namely the inability to find out the selected index. There is a
> >function in the ListBox object called SelectedIndex() which does this,
but

> >not in DropDownListBox...
> >
> >...functionality, unless I am missing something... If somebody knows of

Brett Langston

unread,
Jun 29, 1998, 3:00:00 AM6/29/98
to

I wanted to write my own function, but wasn't able to do so. First, I
thought I would handle the pbm_cbnselchange user event, and track the
selection change that way. However, the pbm_cbnselchange user event does
not exist. It seems as though Sybase left it out by accident, since all of
the other pbm_cbn* notification events are there, including many obscure
ones that most developers wouldn't use.

Looping through all of the items and checking for a match is a good idea.
I had been doing something like this:
item = ddlb_x.FindItem(ddlb_x.Text, 0)
However, this does not work if the list is not sorted, since FindItem only
checks to see if the first part of the item's text matches the parameter,
instead of making sure that the *entire* text string matches the parameter.
For instance, if there were a list with these two items:
#1 Mr. Edwards
#2 selected!----> Mr. Ed
the line of code above would return 1, and not 2. This is a shame, since
the standard Windows drop-down listbox provides the ability to do an exact
match to take care of this very problem (using the CB_FINDSTRINGEXACT
message instead of the CB_FINDSTRING message). However, Sybase decided to
omit this capability, it seems. I'm not sure why they couldn't have
provided an equivalent FindItemExact() function.

Your idea will work quite well though, since by looping through all of the
items, I can perform the exact match test myself. It is too bad that it
needs to be done this way, since there will be so much overhead from
looping through the list. However, since Sybase seems determined to shield
developers from accessing all of a control's built-in events and functions,
it is the only way to do it, and I'm grateful for the advice and quick
answer.

- Brett

Simon <si...@getreal.demon.co.uk> wrote in article
<8HSHCM0...@forums.powersoft.com>...


> Two solutions:
> 1. Write your own function. You can create your own standard DDLB base
> object and add the function to that. You need to loop through all the
items
> and check for a match.
> 2. Use an external dw with a column type of DDDW instead.
>
> I would recommend (2)
>
> Simon
>

Sanjiv Das [TeamPS]

unread,
Jun 29, 1998, 3:00:00 AM6/29/98
to

Brett,

FYI, you can create user events mapped to most windows events. I am not sure
if any are missing, but if they are, you can write code in the Other event
and check the parameter to determine what windows event took place. Writing
code in the Other event is not recommended because it fires for everything
that happens in the application and could slow down performance. It also
makes it difficult to debug the application ( as does the wonderful Activate
event ! ).


HTH

Sanjiv Das [TeamPS]


Brett Langston wrote in message

<01bda38d$2485b2e0$fc00...@babbage.jdacorp.com>...

Daniel

unread,
Jun 30, 1998, 3:00:00 AM6/30/98
to

Hi there

One way to get the selected item in a DDLB is simply accessing the TEXT
attribute of your DDLB.

ls_text = ddlb.text

To get the actual index of that text you would then go

li_index = ddlb.finditem(ls_text,1)

This is the method I use and it has worked fine for me so far and is much
better than looping through the entire list.

Daniel McAlister

0 new messages