|
-
Jul 11th, 2000, 04:11 PM
#1
Thread Starter
Member
Hi. Does anybody know what type of control do I have to use if I need multiple selection on a particular dropdown? I can't use ComboBox since it has no multiple selection property.
I hope you can help me.
Thanks,
-
Jul 11th, 2000, 04:25 PM
#2
Hyperactive Member
Listbox
In VB6 at least, you can use it. Not sure about other versions.
If you size it small enough, so that it is only one visible line, you can have the multiselect without having to take up more room than a combo box.
Don't forget to turn the multi-select property of the list box.
Regards
Paul Lewis
-
Jul 11th, 2000, 04:36 PM
#3
If it doesn't actually have to "drop down" then you can also use the ListView or any of the grids.
-
Jul 11th, 2000, 04:41 PM
#4
Thread Starter
Member
Thanks guys for replying on my question.
PaulLewis, I am trying to use listbox but how can I make it like a combo box? you know, having a dropdown arrow...
MartinLiss, I really need it to be dropdown.
Regards,
-
Jul 11th, 2000, 04:56 PM
#5
Hyperactive Member
-
Jul 11th, 2000, 05:00 PM
#6
Thread Starter
Member
Thanks Paul, I really need this feature since VB6 is not providing multi-select for the combobox control. Can I find the contents of the book that you were telling me in internet? if so, what website?
Thanks a lot!
-
Jul 11th, 2000, 05:32 PM
#7
Hyperactive Member
BEst ready to run example I have found so far
Well,
I looked for any possibility of enabling a VB - crippled feature of a combo box to enable multi select and unfortunately I found that combo boxes do not seem to subclass list boxes even though the documentation says that a "combobox consists of a list box and...".
So there is a very good solution to be found at http://www.vbaccelerator.com/codelib...st/article.htm but I warn you, this is an advanced topic of discussion and the code provided in that link is awesome, but could be akin to fishing with dynamite...
So here is a VB only solution for you. It's not pretty but if you like the idea you should be able to fiddle around and get it working how you want. Although it will never look as polished as a true life multi-select combo box...
Drop this code onto a form which has a small Command1 button and a list box. I put some test data in the list box as well but the example will work without it.
To look right, make certain the command button is "above" the list box. Easiest way is to create the list box first.
Also, make the command button and the listbox have the same "top" property but make the command button have a greater "Left" property.
Code:
Option Explicit
Private Sub Command1_Click()
ToggleListBox
End Sub
Private Sub Form_Load()
HideListBox
End Sub
Private Sub ToggleListBox()
Static isOpen As Boolean
isOpen = Not isOpen
If isOpen Then
ShowListBox
Else
HideListBox
End If
End Sub
Private Sub HideListBox()
' we want to hide the scroll bar behind the command
' button.
List1.Width = Command1.Left - List1.Left + Command1.Width
List1.Height = 255
End Sub
Private Sub ShowListBox()
' we need to make the list box look like it's opened
' note that the scroll bar might be present
List1.Width = Command1.Left - List1.Left
List1.Height = 1620
End Sub
I hope it is of some use. Alot of what programmers do is simply making existing controls do things that they want them to do. This code is a very simple example of this, but you will find all other examples involving API calls and so on, do the same sort of thing. That is, change behaviour to suit their needs.
As an after thought, I thought I would mention that sometimes we must all question the reason for wanting certain behaviour out of a control. A combobox is not provided with multiselect because it is not visually geared to do that (i.e. what should the edit window display when more than one item is selected?). It would make more sense in this case to have the edit window display "Multiple selections" or something to indicate at a glance that there is hidden data in that field.
Just my thoughts on it anyhow. I hope it goes well for you.
Regards
Paul Lewis
-
Jul 12th, 2000, 10:22 AM
#8
Thread Starter
Member
Thanks Paul. This is what I need, my problem now is how can I make the selected text from the listbox be the first record in the list.
I really really appreciate everything. 
Have a nice day,
-
Jul 12th, 2000, 03:41 PM
#9
Hyperactive Member
How I would do it...
Well, if the "pretend" dropdown list example above worked for you (i.e. you don't mind the somewhat slunky look and feel of it) then why not use a similar approach to add a third control to the ensemble? Add a text box or a label, and make this sit above the list box. If you do it this way, then all you need do is hide or show the list box, and make sure that when the list box is hidden, the text box is updated.
If you end up liking what you write, you can make it into your very own custom control (UserControl) and then you will be able to use it like any other control you get on your control pallete. It will be reusable in all your future projects.
If you haven't created a custom control before, there is nothing really hard about it because the wizards do most of it for you 
I'll help you more if you really need it, but with the example I gave, and the idea of addinig a text box, I hope you can get buy 
Regards
Paul Lewis
-
Jul 13th, 2000, 05:43 PM
#10
Thread Starter
Member
Thanks Paul. Actually I just did not use Textbox control and instead I just transferred the selected record to the first line of the listbox and it works.
However, I am adding a picture (bitmap file) on the command button and I am wondering why the picture does not appear on the button. Do you have any idea about this thing?
Thanks again and have a nice evening,
-
Jul 13th, 2000, 06:53 PM
#11
Hyperactive Member
Button is too small/bitmap too big?
You see, it's never easy making things work the way you want 
I don't exactly know why because I have a bitmap which is about 16x16 and contains the "standard" background colour of a button with a black down arrow in it. So it looks more or less like the combo box bitmap.
With no command button caption and with the command button style property set to 1 (Graphical) I can see it fine.
Of course, users with different system colours on their machine will note that you have hard coded the colours of this control. There is no easy way around this unfortunately because VB doesn't support the transparent colour for bitmaps being placed onto buttons (as far as I know)
But if you can live with the odd complaint about the button being grey when the user has "Flouro Pink" as their colour choice...then go for it.
I can mail you my bitmaps if you want them. I just captured them from the VB ones 
Cheers
Paul Lewis
-
Jul 14th, 2000, 07:36 AM
#12
Thread Starter
Member
Yes Paul, thanks, can you e-mail them to me? I will be very glad to have it. 
Take care,
-
Jul 22nd, 2000, 01:34 PM
#13
Thread Starter
Member
Hi again. 
I am trying to create a Listview having records from database... How can I do that? The problem is I don't have enough documentation to study for this and I really have to do it. I am doing a listview wherein a user will just select multiple records from the list. Is this possible in listview? selecting multiple records? even if it can just do a single selection, can you help me out?
Thank you very much, I would be very glad to hear your replies.
Regards,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|