|
-
May 24th, 2007, 07:50 AM
#1
Disable some entries in Combo box
I am loading a combo box with entries from a data base and based on certain conditions, I would like to disable some of the entries in the combo box so that the user may not click on these options. How do I disable some of the entries in the combo box??
Last edited by nthaby; May 24th, 2007 at 07:55 AM.
Reason: remove bold in title
-
May 24th, 2007, 08:01 AM
#2
Re: [bold]Disable some entries in Combo box[/bold]
I think, you can't.
Entries in a combo or a listbox are accessed as cbo.List(n) which retrieves the item string. The only property of these items is if they are selected or not. This property is accessed as cbo.Selected(n).
An 'Enabled' property does not exist. You have to deal with that by software.
-
May 24th, 2007, 09:27 AM
#3
Re: Disable some entries in Combo box
Thank you for your response. In other words, I can't even change colours of certain entries in the combo box?? This is because I thought that if its not possible to disable some entries, then I might change the colour to white so that it may not be visible to the user.. Would you or anyone have other suggestions of how to work around this problem??
 Originally Posted by WoF
I think, you can't.
Entries in a combo or a listbox are accessed as cbo.List(n) which retrieves the item string. The only property of these items is if they are selected or not. This property is accessed as cbo.Selected(n).
An 'Enabled' property does not exist. You have to deal with that by software.
-
May 24th, 2007, 10:40 AM
#4
Re: [bold]Disable some entries in Combo box[/bold]
The problem is, you require a combo-box.
The ListView control from 'Microsoft Windows Common Controls 6.0' provides extensive item properties, but has no dropdown feature...
There are a couple of custom listbox controls available freely in the internet. Try a search with "custom combobox control"
-
May 24th, 2007, 04:14 PM
#5
Re: Disable some entries in Combo box
Just a quick simple thought...
Why not remove the items from the list...
Code:
Combo1.RemoveItem ([ItemIndex])
Just remember to go through the list backwards..
Gremmy..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 24th, 2007, 08:54 PM
#6
Re: Disable some entries in Combo box
 Originally Posted by nthaby
I am loading a combo box with entries from a data base and based on certain conditions, I would like to disable some of the entries in the combo box so that the user may not click on these options. How do I disable some of the entries in the combo box??
this may help little bit more
Code:
'where c is ComboBox
option explicit
Dim CllLocked As New Collection
Const IsLocked As Boolean = True
Private Sub c_Click()
Dim indexCombo As Integer
Dim keyColl As String
indexCombo = c.ListIndex
keyColl = "key" & CStr(indexCombo)
If CllLocked.Item(keyColl) = IsLocked Then
MsgBox "Index is Locked"
End If
End Sub
Private Sub Form_Load()
dim i as integer
For i = 1 To 10
c.AddItem i
CllLocked.Add IIf(i Mod 2 = 0, IsLocked, Not IsLocked), "key" & CStr(i - 1)
Next
End Sub
-
May 24th, 2007, 10:13 PM
#7
Re: [bold]Disable some entries in Combo box[/bold]
Just use a FlexGrid. You can change the color of each cell!
-
May 24th, 2007, 11:58 PM
#8
Re: [bold]Disable some entries in Combo box[/bold]
Or you will have to write your own control (owner drawn control).
Why don't you just remove the items from the combobox if they are not required. You can add them again when you need them.
-
May 25th, 2007, 03:13 AM
#9
Re: [b]Disable some entries in Combo box[/b]
Thanks to everybody who have contributed, I will try out all your suggestions and let you know how if it worked..
-
May 26th, 2007, 11:23 PM
#10
Re: [b]Disable some entries in Combo box[/b]
Dear nthaby,
here i have make some changes in the code given by hensa22, so that the user can't access the disabled selection and index reset to the previous valid seletion, so that c.text propperty also not usable by the user in case of disable selection!
Code:
Option Explicit
Dim CllLocked As New Collection
Const IsLocked As Boolean = True
Dim lastIndex As Integer
Private Sub c_Click()
Dim indexCombo As Integer
Dim keyColl As String
indexCombo = c.ListIndex
keyColl = "key" & CStr(indexCombo)
If CllLocked.Item(keyColl) = IsLocked Then
MsgBox "Index is Locked"
c.ListIndex = lastIndex
Else
lastIndex = c.ListIndex
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 10
c.AddItem i
CllLocked.Add IIf(i Mod 2 = 0, IsLocked, Not IsLocked), "key" & CStr(i - 1)
Next
End Sub
 Originally Posted by nthaby
Thanks to everybody who have contributed, I will try out all your suggestions and let you know how if it worked..
And hensa22 , ur code was so good...thanks for sharing with us!
I'M BACK AGAIN !!
-------------------------------------------------------------------------
enjoy the VB ! 
If any post helps you, please rate that.
Always try to findout the Solutions, instead just discussing the problem and its scope!

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
|