CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Mar 2001
    Posts
    15

    Combo box (Forms 2.0 Object Library)

    I'm using a combo box (Microsoft Forms 2.0 Object Library) that has the property of being able to Match Entry by the First Letter. This combo object doesn't support the property of .ItemData or .NewIndex.

    Using this combo box I want to save the index to the selected item. Can anyone help me?

    Thank-u,
    Donna

  2. #2
    Join Date
    Aug 2006
    Posts
    145

    Re: Combo box (Forms 2.0 Object Library)

    Are you doing this in VB6 or VBA?

  3. #3
    Join Date
    Dec 2004
    Posts
    423

    Re: Combo box (Forms 2.0 Object Library)

    Just store the index in a public variable of the form on the change event

    Code:
    Public MyIndex as Long
    
    Private Sub MyCombo_Change()
    	MyIndex = MyCombo.ListIndex
    End Sub
    Even if everybody spoke the same language, nobody would be speaking the same language.

    --Daniel

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Combo box (Forms 2.0 Object Library)

    Quote Originally Posted by bushmobile
    Are you doing this in VB6 or VBA?
    Basically you can add a class where you have each item and its index and if you whish, also some other data too.

    But isn't Forms2 basically for VBA ? As I remember, when used in VB in compiled programs in a programs setup, I got troubles to distribute the code to other machines.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Combo box (Forms 2.0 Object Library)

    It's part of Office, so you can't distribute it. Use the VB6 control instead.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Mar 2001
    Posts
    15

    Re: Combo box (Forms 2.0 Object Library)

    I'm using VB6 and I want to store the index for each item in the list. For other combo boxes I use:

    With frmNice
    While Not rs.EOF
    .cboStatus.AddItem rs!Description
    .cboStatus.ItemData(.cboStatus.NewIndex) = rs!Key
    rs.MoveNext
    Wend
    End With

    I added this code instead, but am having trouble extracting the index to the selected item.

    iindex = 0
    With frmNice
    While Not rs.EOF
    .cboStatus.AddItem rs!Description
    .cboStatus.List(iindex,1) = rs!Key
    iindex = iindex + 1
    rs.MoveNext
    Wend
    End With

    I tend to make things harder than they really are! thanx again.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Combo box (Forms 2.0 Object Library)

    There is no array. You have to use the ItemData(x) field.

    Code:
      For x = 0 To 5
    	List1.AddItem Chr$(34) & x & Chr$(34)
    	List1.ItemData(x) = 0
      Next x
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Mar 2001
    Posts
    15

    Re: Combo box (Forms 2.0 Object Library)

    The combo box from Forms 2.0 Object Library, does not support that property.

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Combo box (Forms 2.0 Object Library)

    Why don't you use the Windows Combo instead? Otherwise, create an array for the key. Use the same index as the combobox.

    I often load fields into array fieldnames, so I don't have to get them from the db more than once.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Combo box (Forms 2.0 Object Library)

    Quote Originally Posted by donna_H
    I'm using VB6 and I want to store the index for each item in the list. ...
    I'm again coming back to the point you cannot distribute a VB6 program which uses form2 controls. I kne that the hanling of the forms2 combo is near to an autocomplete combobox, but it has other problems as you see. Or do you need the program only for your own usage ? Or would you distribute it only together with the office package. In this case you would need to tell people to first install office and then installing your program. But I'm not sure if in new office versions there are still form2 controls.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Combo box (Forms 2.0 Object Library)

    It will NOT install on other machines, and the program will only run if the identical version of Word is running. It is ILLEGAL to distribute some controls that other apps use. Use the VB6 controls for free!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: Combo box (Forms 2.0 Object Library)

    Quote Originally Posted by dglienna
    It will NOT install on other machines, and the program will only run if the identical version of Word is running. It is ILLEGAL to distribute some controls that other apps use. Use the VB6 controls for free!
    While you can't distribute Forms 2.0, it doesn't require Office, and it doesn't mean your distributed app can't use it.
    Quote Originally Posted by ChaosTheEternal
    There is a Component available, though, called Forms 2.0, ..., but it is not directly distributable. See this Microsoft article about how to distribute it (or to basically sum [the article] up, it requires end users to install, at the very least, the MS ActiveX Control Pad, or to already have a version of Office newer than 97), and where to download it.
    But, I'd agree, a Forms 2.0 combo box is not the way to go. The standard VB combo box should work, even if you need something in the back end to help out with your goal, like an array (as dglienna suggested).

  13. #13
    Join Date
    Aug 2006
    Posts
    145

    Re: Combo box (Forms 2.0 Object Library)

    Even if redistribution isn't an issue, you shouldn't use the Forms 2.0 object library - it's unstable in the VB6 environment with a tendency for "out of memory" errors - MS advise against its use.

  14. #14
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Combo box (Forms 2.0 Object Library)

    Quote Originally Posted by bushmobile
    --- you shouldn't use the Forms 2.0 object library - it's unstable in the VB6 environment with a tendency for "out of memory" errors - MS advise against its use.
    Exactly whats my experience.

    If you dont have hundrtets of items to load into your combo but you need an autocomplete Combobox you can try to use the ActiveX Combo control which is designed in the thread
    http://www.codeguru.com/forum/showpo...&postcount=123
    Lesson 14 is the last version of the combo. If you want to look how to design such a Userdefined control, you can follow up the whole thread.
    You will learn to create your own classes and collections so it would be easy for you to administrate very complex data if you need to do so.

    Jonny Poet
    Last edited by JonnyPoet; March 15th, 2007 at 07:21 PM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  15. #15
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Combo box (Forms 2.0 Object Library)

    Been there, done that already also. Too much grief. Heed our advice!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured