Disable Some List Items from Combo Box !!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hiren Joshi
    New Member
    • Feb 2008
    • 30

    Disable Some List Items from Combo Box !!!

    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)
    Last edited by debasisdas; Feb 12 '08, 11:07 AM. Reason: Removed mail id
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to Visual Basic Forum from VB Articles Section.

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      You need to use ITEMDATA property of the control.

      Comment

      • Hiren Joshi
        New Member
        • Feb 2008
        • 30

        #4
        Hi Debasis,

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

        Thanks,

        Hiren

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          1.Set ItemDate property for desired items in the collection.
          2.Check for the same in the click event and execute the further code.

          Comment

          • Hiren Joshi
            New Member
            • Feb 2008
            • 30

            #6
            Sorry but Still i dont have clear idea of it, if you can write for me a sample here.

            Thanks in Advance

            Hiren

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              Kindly post the code that you have tried so far.

              Comment

              • Hiren Joshi
                New Member
                • Feb 2008
                • 30

                #8
                On Form Load Event My Code Follows:

                If Xrs.State = adStateOpen Then Xrs.Close
                Xrs.CursorLocat ion = adUseClient
                Xrs.Open "select * from Table1 Order By SrNo", Con, adOpenKeyset, adLockOptimisti c

                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

                Comment

                • debasisdas
                  Recognized Expert Expert
                  • Dec 2006
                  • 8119

                  #9
                  Try to follow the sample code

                  [code=vb]
                  Private Sub Command1_Click( )
                  i = List1.ListIndex
                  If List1.ItemData( i) <> 10 Then
                  List2.AddItem List1.List(List 1.ListIndex)
                  Else
                  MsgBox "Can''t add This Item"
                  End If

                  End Sub

                  Private Sub Form_Load()
                  For i = 1 To 10
                  List1.AddItem i
                  Next i
                  List1.ItemData( 3) = 10
                  List1.ItemData( 5) = 10
                  List1.ItemData( 7) = 10
                  End Sub

                  [/code]

                  Comment

                  • Hiren Joshi
                    New Member
                    • Feb 2008
                    • 30

                    #10
                    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

                    Comment

                    • debasisdas
                      Recognized Expert Expert
                      • Dec 2006
                      • 8119

                      #11
                      It does not matter of the item is enabled or not . Our aim is to make that not selectable by the user.

                      Comment

                      • Hiren Joshi
                        New Member
                        • Feb 2008
                        • 30

                        #12
                        Ok Sir,

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

                        Regards,

                        Hiren

                        Comment

                        Working...