469,947 Members | 2,285 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,947 developers. It's quick & easy.

Disable Some List Items from Combo Box !!!

Hiren Joshi
Hello All Experts,

I am a Moderate VB Programmer. I am developing one Application at the moment with VB 6.0 and MS Access. Operating System is Win XP. Its a Multi User application.

What I want to know is How do I Disable 2 or 3 Items from Combo Box?

I am using Combo Box with Style 2. and all Fields come from Access Table while loading the form. (e.g. If My List is A0, A1, A2, A3, A4...) and at run time if i want to Disable A1 and A3 from Selecting... Is it possible to do so?

Your quick response on this matter will be highly appreciated,

You can email me as well on mail id removed

Thanks & Regards,

Hiren (Nairobi - Kenya)
Feb 12 '08 #1
11 5677
debasisdas
8,127 Expert 4TB
Question moved to Visual Basic Forum from VB Articles Section.
Feb 12 '08 #2
debasisdas
8,127 Expert 4TB
You need to use ITEMDATA property of the control.
Feb 12 '08 #3
Hi Debasis,

Can you please tell me which ITEMDATA Propery I am supposed to use? Please if you can specify in details.

Thanks,

Hiren
Feb 12 '08 #4
debasisdas
8,127 Expert 4TB
1.Set ItemDate property for desired items in the collection.
2.Check for the same in the click event and execute the further code.
Feb 12 '08 #5
Sorry but Still i dont have clear idea of it, if you can write for me a sample here.

Thanks in Advance

Hiren
Feb 12 '08 #6
debasisdas
8,127 Expert 4TB
Kindly post the code that you have tried so far.
Feb 12 '08 #7
On Form Load Event My Code Follows:

If Xrs.State = adStateOpen Then Xrs.Close
Xrs.CursorLocation = adUseClient
Xrs.Open "select * from Table1 Order By SrNo", Con, adOpenKeyset, adLockOptimistic

If Xrs.RecordCount <> 0 Then
Xrs.MoveFirst

While Xrs.EOF = False
Combo1.AddItem (Xrs("Name"))
Xrs.MoveNext
Wend
End If
'===================
and at run time it displays Value in Como1 like A0, A1, A2, A3, A4, A5, A6... Now I want A1 and A3 to be disabled... That means If I click on Combo1 I should be able to select all other values apart from A1 and A3.....

Hiren
Feb 12 '08 #8
debasisdas
8,127 Expert 4TB
Try to follow the sample code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. i = List1.ListIndex
  3. If List1.ItemData(i) <> 10 Then
  4. List2.AddItem List1.List(List1.ListIndex)
  5. Else
  6. MsgBox "Can''t add This Item"
  7. End If
  8.  
  9. End Sub
  10.  
  11. Private Sub Form_Load()
  12. For i = 1 To 10
  13. List1.AddItem i
  14. Next i
  15. List1.ItemData(3) = 10
  16. List1.ItemData(5) = 10
  17. List1.ItemData(7) = 10
  18. End Sub
  19.  
  20.  
Feb 12 '08 #9
Yes Debasis,

This Works as well... But Can't it become Disable so that there is no chance of even selecting that Item even by Mistake?

But so far this code works,

Thanks,

Hiren
Feb 12 '08 #10
debasisdas
8,127 Expert 4TB
It does not matter of the item is enabled or not . Our aim is to make that not selectable by the user.
Feb 12 '08 #11
Ok Sir,

That was a question just to know for my knowledge. Anyway Thank You once again for this help too.

Regards,

Hiren
Feb 12 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Peter Collinson | last post: by
2 posts views Thread by Unknown User | last post: by
5 posts views Thread by Ike | last post: by
2 posts views Thread by Claudia Fong | last post: by
reply views Thread by c0mrade | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.