|
-
Dec 20th, 2007, 01:18 PM
#1
Thread Starter
Lively Member
Access style multi-column listbox
I'm in the process of converting an Access 2000 front-end to VB6. I've got quite a bit of VBA experience, but am only just starting out with VB6. Anyway, I've already hit a bit of a stumbling block as I notice that VB6 listboxes do not behave the same way as Access listboxes. The Access front-end I need to convert uses them extensively as listboxes tend to work faster than continuous forms (in Access). Is there an accepted way I should be converting the Access listboxes to VB6? I've done a lot of searching, but to no avail. I need to have multi-column listboxes that also have a hidden column (key field). For example, I have a list of clients in a listbox, and when the user double clicks on a client, the hidden column (key field) is used to populate the rest of the form. Any help much appreciated.
-
Dec 20th, 2007, 01:20 PM
#2
Re: Access style multi-column listbox
Welcome to the forums. 
There are no multi column Listboxes in VB6. This is something I've always felt was sorely lacking and yet another cause for me to believe that often the development teams never talked to each other.
Anyway, in VB6, use the ListView control. It will do what you need.
-
Dec 20th, 2007, 02:00 PM
#3
Thread Starter
Lively Member
Re: Access style multi-column listbox
Thanks, the ListView control seems exactly what I was looking for. And thanks for the welcome!
-
Dec 20th, 2007, 02:02 PM
#4
Re: Access style multi-column listbox
You are welcome. 
The ListView syntax differs somewhat from the ListBox, but if you run into any issues, just post a question.
If you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you.
-
Dec 20th, 2007, 02:54 PM
#5
Thread Starter
Lively Member
Re: Access style multi-column listbox
I've managed to populate the ListView with items from a recordset, however, how can I obtain the Key value of the selected item (for example, when the user double clicks an item)? Also, I noticed that when assigning a Key, it has to contain an alpha character, it wouldn't accept a numerical value. I tried converting the numerical value to a string but it still wouldn't let me use it unless I put an alpha-prefix before the number.
-
Dec 20th, 2007, 03:07 PM
#6
Re: Access style multi-column listbox
You can check for the items selected by looping through the ListItems collection checking for the .Selected property to be true.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 20th, 2007, 03:14 PM
#7
Thread Starter
Lively Member
Re: Access style multi-column listbox
Is there a simpler method if the user can only select one item at a time?
-
Dec 20th, 2007, 03:58 PM
#8
Re: Access style multi-column listbox
Well a combo box control is the simpliest but only single column'ed. A listview is really not that difficult to work with.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 20th, 2007, 04:59 PM
#9
Re: Access style multi-column listbox
 Originally Posted by bcass
Is there a simpler method if the user can only select one item at a time?
From ListView Properties window, uncheck [ ] Multi Select box.
or by code:
Code:
ListView1.MultiSelect = False
-
Dec 20th, 2007, 05:06 PM
#10
Thread Starter
Lively Member
Re: Access style multi-column listbox
Sorry, I just meant how could I get the Key value of the item the user selected, here's how I ended up doing it:
Code:
lvwViewList.SelectedItem.Key
However, now I'm stuck again - how can I change the width of the column (I only have 1 column in this particular ViewList)? Also, I am not showing ColumnHeaders, if that makes any difference?
-
Dec 20th, 2007, 05:25 PM
#11
Re: Access style multi-column listbox
ListView1.ColumnHeaders(1).Width = 3000
I've managed to populate the ListView with items from a recordset, however, how can I obtain the Key value of the selected item (for example, when the user double clicks an item)?
You could use the ListItem.Tag property. The Tag property is a Variant and can contain any data type required by an application.
Code:
Private Sub Form_Load()
Dim oItem As ListItem
Set oItem = ListView1.ListItems.Add(, , "Some Text")
oItem.Tag = 12345
End Sub
Private Sub ListView1_DblClick()
MsgBox ListView1.SelectedItem.Tag
End Sub
Last edited by brucevde; Dec 20th, 2007 at 05:33 PM.
-
Dec 20th, 2007, 06:14 PM
#12
Thread Starter
Lively Member
Re: Access style multi-column listbox
 Originally Posted by brucevde
ListView1.ColumnHeaders(1).Width = 3000
I actually tried that before posting, but I get the error "Index out of bounds". I'm using the lvwReport View of the ListView if that might be affecting anything?
-
Dec 20th, 2007, 06:33 PM
#13
Re: Access style multi-column listbox
You must have at least 1 Column when using lvwReport view.
ColumnHeaders is a collection and collections are 1 based.
-
Dec 20th, 2007, 06:49 PM
#14
Thread Starter
Lively Member
Re: Access style multi-column listbox
I have 1 column (the data is showing) but I'm not showing ColumnHeader. Are you saying it can only be done if you show the ColumnHeader?
-
Dec 20th, 2007, 07:23 PM
#15
Re: Access style multi-column listbox
With or without showing column headers, you always can set ColumnHeaders(1).Width = ...
-
Dec 21st, 2007, 06:03 AM
#16
Thread Starter
Lively Member
Re: Access style multi-column listbox
Any idea why I'm getting the "Index out of bounds" error message then?
-
Dec 21st, 2007, 06:09 AM
#17
Re: Access style multi-column listbox
.Text is column 1
.Subitems(1) or .ListSubItems(1) is column 2
.Subitems(2) or .ListSubItems(2) is column 3
and so on and so forth... you can check with ListView1.ColumnHeaders.Count adjusted accordingly (less 1 in order to correspond with indices of Subitems).
As to the error with ColumnHeaders collection, how did you create the column? In the IDE at design time or programmatically at run-time... if at run-time, was the column already created before you tried changing the width? Are you referencing the correct listview in the GUI?
As to the listitem key, you can easily get rid of the prepended character with Mid(Key, 2) to get the numeric ID rather than iterating through the listview.
Last edited by leinad31; Dec 21st, 2007 at 06:15 AM.
-
Dec 21st, 2007, 06:28 AM
#18
Thread Starter
Lively Member
Re: Access style multi-column listbox
 Originally Posted by leinad31
As to the listitem key, you can easily get rid of the prepended character with Mid(Key, 2) to get the numeric ID rather than iterating through the listview.
Yep, that's what I'd already ended up doing. Just seemed a bit odd that I couldn't use only a numerical value, even when it was assigned to a string variable.
Anyway, I found out what the problem was with setting the ColumnHeaders - I was trying to define the column width before adding any items to the ListView... I tried it after adding items, and it works perfectly. Thanks for all the help.
Last edited by bcass; Dec 21st, 2007 at 06:32 AM.
-
Dec 21st, 2007, 11:05 AM
#19
Frenzied Member
Re: Access style multi-column listbox
Just something I came across, so if somebody is searching this thread at a later date here is a multicolumn (and more) listbox.
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
|