Home > Archive > Visual Basic Controls > January 2006 > Comboboxes and Listboxes - Deciding Between Them
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Comboboxes and Listboxes - Deciding Between Them
|
|
| Bookreader 2006-01-27, 4:01 am |
| I have been playing around with listboxes and comboboxes trying to
figure something out.
Please correct me where I am wrong. Some things I thought were true
may not be.
I always thought that comboboxes were inherited from listboxes.
Therefore, I thought that comboboxes would have all the properties and
methods of listboxes.
The current case is that I have a list of items of which the user is
only allowed to pick one.
In a listbox, I can set the MultiSelect Property to '0' (none) and
then show the item selected by simply:
MsgBox lstFamilies.List(lstFamilies.ListIndex)
This will show me which item was selected.
On the other hand, I like the combo box. Here, I can get it with the
ComboBox.Text method.
Is the combobox not a descendant of the listbox?
It's not a real big deal, but it has me wondering.
Thanks.
| |
| Bookreader 2006-01-27, 4:01 am |
| On Fri, 27 Jan 2006 04:28:37 GMT, Bookreader <bookreader127@yahoo.com>
wrote:
>I have been playing around with listboxes and comboboxes trying to
>figure something out.
>
>Please correct me where I am wrong. Some things I thought were true
>may not be.
>
>I always thought that comboboxes were inherited from listboxes.
>Therefore, I thought that comboboxes would have all the properties and
>methods of listboxes.
>
>The current case is that I have a list of items of which the user is
>only allowed to pick one.
>
>In a listbox, I can set the MultiSelect Property to '0' (none) and
>then show the item selected by simply:
>
> MsgBox lstFamilies.List(lstFamilies.ListIndex)
>
>This will show me which item was selected.
>
>On the other hand, I like the combo box. Here, I can get it with the
>ComboBox.Text method.
>
>Is the combobox not a descendant of the listbox?
>
>It's not a real big deal, but it has me wondering.
>
>Thanks.
| |
|
|
"Bookreader" <bookreader127@yahoo.com> wrote in message
news:9f8jt1h0a6hnql5oapc1uatsp51dvpk4r3@
4ax.com...
>I have been playing around with listboxes and comboboxes trying to
> figure something out.
>
> Please correct me where I am wrong. Some things I thought were true
> may not be.
>
> I always thought that comboboxes were inherited from listboxes.
> Therefore, I thought that comboboxes would have all the properties and
> methods of listboxes.
>
> The current case is that I have a list of items of which the user is
> only allowed to pick one.
>
> In a listbox, I can set the MultiSelect Property to '0' (none) and
> then show the item selected by simply:
>
> MsgBox lstFamilies.List(lstFamilies.ListIndex)
>
> This will show me which item was selected.
>
> On the other hand, I like the combo box. Here, I can get it with the
> ComboBox.Text method.
>
> Is the combobox not a descendant of the listbox?
No, it's not. Each is a distinct and separate control. VB's ListBox and
ComboBox controls are derived from controls that are built-in to Windows.
See the following documentation topics for each:
http://msdn.microsoft.com/library/e.../comboboxes.asp
http://msdn.microsoft.com/library/e...s/listboxes.asp
The Text property of a ComboBox returns whatever is assigned to the edit box
of the control. Since a ListBox doesn't have an edit box, there's no Text
property. This may or may not match the text of an item that's been added
to the ComboBox. For a "Listbox-like" ComboBox, set the CB's Style property
to 2- Dropdown List.
If you really wanted to, you *could* wrap the ListBox in a UserControl and
provide a Text property. Probably more trouble than it's worth unless you
also add even more functionality to it.
--
Mike
Microsoft MVP Visual Basic
| |
|
| I don't know where you two bought your copies of VB from, but I know my one
HAS a Text property for ListBoxes which returns the content of the selected
item.
Regards
Dave O.
"MikeD" <nobody@nowhere.edu> wrote in message
news:uBHOuzyIGHA.2320@TK2MSFTNGP11.phx.gbl...
>
> "Bookreader" <bookreader127@yahoo.com> wrote in message
> news:9f8jt1h0a6hnql5oapc1uatsp51dvpk4r3@
4ax.com...
>
>
> No, it's not. Each is a distinct and separate control. VB's ListBox and
> ComboBox controls are derived from controls that are built-in to Windows.
> See the following documentation topics for each:
>
> http://msdn.microsoft.com/library/e.../comboboxes.asp
> http://msdn.microsoft.com/library/e...s/listboxes.asp
>
> The Text property of a ComboBox returns whatever is assigned to the edit
> box of the control. Since a ListBox doesn't have an edit box, there's no
> Text property. This may or may not match the text of an item that's been
> added to the ComboBox. For a "Listbox-like" ComboBox, set the CB's Style
> property to 2- Dropdown List.
>
> If you really wanted to, you *could* wrap the ListBox in a UserControl and
> provide a Text property. Probably more trouble than it's worth unless you
> also add even more functionality to it.
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>
| |
| Bookreader 2006-01-27, 7:04 pm |
| On Fri, 27 Jan 2006 14:57:39 -0000, "Dave" <nobody@nowhere.com> wrote:
>I don't know where you two bought your copies of VB from, but I know my one
>HAS a Text property for ListBoxes which returns the content of the selected
>item.
>
>Regards
>Dave O.
You're right. I wrote that on the fly after a frustrating several
hours of coding.
Text property was not a good example.
I think we did resolve that the combobox is not descended from the
list box.
Thanks for your reply.
Bookreader
| |
|
|
"Dave" <nobody@nowhere.com> wrote in message
news:eJHZFI1IGHA.3192@TK2MSFTNGP10.phx.gbl...
>I don't know where you two bought your copies of VB from, but I know my one
>HAS a Text property for ListBoxes which returns the content of the selected
>item.
How about that. It most certainly does. Goes to show how much I ever use a
ListBox. <g> Actually, I don't think anything I've written in the last 4
or 5 years has ever used a ListBox. Live and learn.
--
Mike
Microsoft MVP Visual Basic
|
|
|
|
|