![]() |
Userform Listbox subcategories?
Hi,
I was wondering if there was a way to make a value in a listbox - not selectable. Example. I have 2 types of forms--Property Coverage, Liability Coverage I want my Listbox to look like this (the [ ] are the checkboxes that I enabled in Listbox.ListStyle fmListStyleOption) Property Coverage---- [ ] Form #PC001 [ ] Form #PC002 [ ] Form #PC003 Liability Coverage---- [ ] Form #LC001 [ ] Form #LC002 [ ] Form #LC003 Of course the list items "Property Coverage---" and "Liability Coverage----" are just category dividers, and should not be selected (nor should it have a checkbox next to it either). I have seen some web sites that have this; and when users click on the categories, all sub-items are added, but I do not want to enable this option for my users (I want them to make sure they know exactly which forms they're selecting, and not blindly selecting all). I'm also incorporating a 2nd Listbox, and passing the selected values over to the 2nd Listbox (this is common seen in forms with 4 buttons that represent MoveItemLeft, MoveAllLeft, MoveItemRight, MoveAllRight), in case this information is needed. Please help as soon as possible. Thank you in advance! |
Userform Listbox subcategories?
I think the best you can do is to uncheck the box after it's been selected. And
that won't help if you're moving the selected items to a different listbox. This is the way I'd uncheck the item: Option Explicit Dim BlkProc Private Sub CommandButton1_Click() Unload Me End Sub Private Sub ListBox1_Change() Dim iCtr As Long If BlkProc = True Then Exit Sub End If With Me.ListBox1 For iCtr = 0 To .ListCount - 1 If .Selected(iCtr) Then If Right(.List(iCtr), 4) = "----" Then 'unselect it 'stop looking for changes BlkProc = True .Selected(iCtr) = False 'start looking for changes BlkProc = False End If End If Next iCtr End With End Sub Private Sub UserForm_Initialize() With Me.ListBox1 .ListStyle = fmListStyleOption .MultiSelect = fmMultiSelectMulti .AddItem "Property Coverage----" .AddItem " Form #PC001" .AddItem " Form #PC002" .AddItem " Form #PC003" .AddItem "Liability Coverage----" .AddItem " Form #LC001" .AddItem " Form #LC002" .AddItem " Form #LC003" End With End Sub I'm not sure how you're going to handle the moveitemright and moveitemleft, though. Susan wrote: Hi, I was wondering if there was a way to make a value in a listbox - not selectable. Example. I have 2 types of forms--Property Coverage, Liability Coverage I want my Listbox to look like this (the [ ] are the checkboxes that I enabled in Listbox.ListStyle fmListStyleOption) Property Coverage---- [ ] Form #PC001 [ ] Form #PC002 [ ] Form #PC003 Liability Coverage---- [ ] Form #LC001 [ ] Form #LC002 [ ] Form #LC003 Of course the list items "Property Coverage---" and "Liability Coverage----" are just category dividers, and should not be selected (nor should it have a checkbox next to it either). I have seen some web sites that have this; and when users click on the categories, all sub-items are added, but I do not want to enable this option for my users (I want them to make sure they know exactly which forms they're selecting, and not blindly selecting all). I'm also incorporating a 2nd Listbox, and passing the selected values over to the 2nd Listbox (this is common seen in forms with 4 buttons that represent MoveItemLeft, MoveAllLeft, MoveItemRight, MoveAllRight), in case this information is needed. Please help as soon as possible. Thank you in advance! -- Dave Peterson |
Userform Listbox subcategories?
Thanks a bunch for the unselecting idea! I didn't think of it at all. I'll
play around with that then. This means that I will not be able to use the checkbox property for my list items since the categories will have it too (when users see a checkbox, they're going to want to click it!). And you're also right about the moveitemleft and moveitemright. The only idea I have right now is to take in the selected values into a hidden worksheet, and then feed only the items without the "----" into ListBox2. But again, thanks for the hint! Cheers! "Dave Peterson" wrote: I think the best you can do is to uncheck the box after it's been selected. And that won't help if you're moving the selected items to a different listbox. This is the way I'd uncheck the item: Option Explicit Dim BlkProc Private Sub CommandButton1_Click() Unload Me End Sub Private Sub ListBox1_Change() Dim iCtr As Long If BlkProc = True Then Exit Sub End If With Me.ListBox1 For iCtr = 0 To .ListCount - 1 If .Selected(iCtr) Then If Right(.List(iCtr), 4) = "----" Then 'unselect it 'stop looking for changes BlkProc = True .Selected(iCtr) = False 'start looking for changes BlkProc = False End If End If Next iCtr End With End Sub Private Sub UserForm_Initialize() With Me.ListBox1 .ListStyle = fmListStyleOption .MultiSelect = fmMultiSelectMulti .AddItem "Property Coverage----" .AddItem " Form #PC001" .AddItem " Form #PC002" .AddItem " Form #PC003" .AddItem "Liability Coverage----" .AddItem " Form #LC001" .AddItem " Form #LC002" .AddItem " Form #LC003" End With End Sub I'm not sure how you're going to handle the moveitemright and moveitemleft, though. Susan wrote: Hi, I was wondering if there was a way to make a value in a listbox - not selectable. Example. I have 2 types of forms--Property Coverage, Liability Coverage I want my Listbox to look like this (the [ ] are the checkboxes that I enabled in Listbox.ListStyle fmListStyleOption) Property Coverage---- [ ] Form #PC001 [ ] Form #PC002 [ ] Form #PC003 Liability Coverage---- [ ] Form #LC001 [ ] Form #LC002 [ ] Form #LC003 Of course the list items "Property Coverage---" and "Liability Coverage----" are just category dividers, and should not be selected (nor should it have a checkbox next to it either). I have seen some web sites that have this; and when users click on the categories, all sub-items are added, but I do not want to enable this option for my users (I want them to make sure they know exactly which forms they're selecting, and not blindly selecting all). I'm also incorporating a 2nd Listbox, and passing the selected values over to the 2nd Listbox (this is common seen in forms with 4 buttons that represent MoveItemLeft, MoveAllLeft, MoveItemRight, MoveAllRight), in case this information is needed. Please help as soon as possible. Thank you in advance! -- Dave Peterson |
All times are GMT +1. The time now is 11:15 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com