• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

Help with CoolXP and using XpCombo box

I am evaluating if this OCX is a good idea to use in my project but already I have hit into a snag, The normal command Combo1.Listindex
used in VB to find the items index number does not seem to work with CoolXP.  Using xpCombo1.Listindex returns (-1) at all times.  Is there a way to get the Index number in a combo list using CoolXp Combo?
I have tried there web site but it's in German and even with google translation I found nothing useful.
0
jgarth
Asked:
jgarth
  • 6
  • 2
1 Solution
 
gecko_au2003Commented:
What is there website ?
0
 
GPrentice00Commented:
An absolutely bare project, with just a form and default xpCombo  box, populated at runtime:  (Using the 2.7.71 version of the xpcombo; http://www.vb-fun.de/cgi-bin/loadframe.pl?ID=vb/komponenten/komponente0056.shtml)

Private Sub Form_Load()
    Me.xpCombo1.ItemsAddMulti 0, "red", "blue", "green", "yellow", "orange", "white"
    Debug.Print "nothing selected yet: "; Me.xpCombo1.ListIndex    
End Sub

Private Sub xpCombo1_Change()
    Debug.Print "Picked indexed item #: "; Me.xpCombo1.ListIndex;
    Debug.Print Me.xpCombo1.List(Me.xpCombo1.ListIndex)
End Sub

=====================================
Works exactly as it should - returns the correct index value when I click on "green"
nothing selected yet: -1
Picked indexed item #:  2 green


Under what context are you trying to examine a return and its failing?

0
 
jgarthAuthor Commented:
Yes works fine so long as its a dropdown type control otherwise it has big Bug in it.
Sorry to be Negative but I spent 8 hours coding around this Combo and now I get to a point and find it has a huge limitation ..... !!  Christ I am going to have to ditch tons of code just to remove and revert.

DO you know if there is any English Documentation on CoolXP?

Try this and you will see the problem

Private Sub Form_Load()
    Me.xpCombo1.Style = cEasyCombination
    Me.xpCombo1.Height = 1600
    Me.xpCombo1.ItemsAddMulti 0, "red", "blue", "green", "yellow", "orange", "white"
    Debug.Print "nothing selected yet: "; Me.xpCombo1.ListIndex    
End Sub

Private Sub xpCombo1_Change()
    Debug.Print "Picked indexed item #: "; Me.xpCombo1.ListIndex;
    Debug.Print Me.xpCombo1.List(Me.xpCombo1.ListIndex)
End Sub

Private Sub xpCombo1_Click()
   MsgBox "Picked indexed item #: " & Me.xpCombo1.ListIndex
End Sub




0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
GPrentice00Commented:
Nothing to apologize for at this point...

The only Eng documentation I've seen is that which gets installed with the CoolXP package, which has a toggle from German to English link.  Each control does provide a clickable link in its About box, but from there, they rapidly degrade into German forums...
My documentation infact only describes the combobox   .listindex  property as  a settable one, does not show a get-case sample as others do, although as we both know, it does function as it should for a listbox/combobox control in the default cDropdowncombo and cDropDownList modes.  Indeed, the EasyCombination mode has very little to work with (although setting  me.xpcombo1.listindex = 4 in some code somewhere will cause the textbox part to display 'orange' and select 'orange' from the list, thats of little help without the ability to detect the index, absolutely!)

That was after all the reason for the additional "under what context"

I have spent the better part of 90mins or so trying to adapt some API calls on comboboxes and listboxes to try to pull out something from the xpcombobox witout success, but suspect that that will be the solution path -- it will be necessary to identify the windows message for it first, and I don't have that tool reinstalled on my couple month old computer yet.  I've also tried some code to convert mouse-positions on a list into indices with no success either yet.

Documenation or not, there are not a lot of methods and properties with the control that even provide something to use in thix context, even though they do have some nice events that isolate it (my kingdom for  the listclick event to be listclick(index as integer)!!! ), but if you can use one of the two other styles which are more like the traditional comboboxes...

As stands, appears to be a bug with that mode perhaps, althought the documentation does seem to overlook the use of listindex as a return value in general.

0
 
GPrentice00Commented:
Using WInspectorSpy it seems that the xpcombo in the ccEasyCombination mode has a listbox window child in it, so it should be possible using the right API calls to pull the index/value out of that.  Getting the right child window will be just a matter of a child-enum function.  I have been away all evening, and it grows late, but I will try for about an hour or so to make it work now, as its a personal challange.  If unable to do anything tonight, I will continue to chip away tomorrow night if that is not too late, or if you can understand what I mean about the child windows of the control and can go from there, power to you -- gotta go down a couple layers and get the right hwnd, but should be standard listbox-api calls from there.
0
 
GPrentice00Commented:
Okay - I got it!  You just need to copy/paste some code from below, and make a tweak to your combobox click/ listclick events, and we have a patch!

I'm posting a COMPLETE working project continuation from above.  I've modified it to be Generic so you can pass any xpcombobox and not have to duplicate a lot of code.  My project has two xpcomboboxes on it.

Please feel free to experiment from here.  Thanks for the challange, hope it helps you.

=======================
=======================
Form module Code
======================
Private Sub Form_Load()
    Me.xpCombo1.Style = cEasyCombination
    Me.xpCombo1.Height = 1600
    Me.xpCombo1.Style = cEasyCombination
    Me.xpCombo1.Height = 1600
    Me.xpCombo1.ItemsAddMulti 0, "red", "pink", "blue", "mauve", "peach", "white"
    Me.xpCombo2.ItemsAddMulti 0, "tan", "lavender", "green", "yellow", "orange"
End Sub

Private Sub xpCombo1_Click()
    XPCIndexer.ShowIndexed xpCombo1
End Sub

Private Sub xpCombo2_Click()
    XPCIndexer.ShowIndexed xpCombo2
End Sub


========================================
========================================
MODULE CODE -- MAKE A NEW MODULE AND CALL IT   XPCIndexer
===========================================

Option Explicit
' Code seriously simplified for enumeration from AllApi.net example.
' With WInspector Spy tool, identified that XPCombo always enumerates childs the same way
'  and the second last enumerated window is the listbox with an indexable value
' From there, its API calls to get the lisbox selection index for that hwnd

' The following code is put into a module called   XPCIndexer

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private LastHWND As Long
Private SecondLastHWND As Long
Const LB_GETCURSEL As Long = &H188

Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    SecondLastHWND = LastHWND
    LastHWND = hwnd
    EnumChildProc = 1
End Function

Public Function GetHwndOfXPComboLB(ByRef xpc As xpCombo) As Long
    EnumChildWindows xpc.hwnd, AddressOf EnumChildProc, ByVal 0&
    GetHwndOfXPComboLB = XPCIndexer.SecondLastHWND
End Function

Public Function SelectedIndex(ByVal hwnd As Long) As Integer
     Dim index As Long
     index = SendMessage(hwnd, LB_GETCURSEL, ByVal 0&, ByVal 0&)
     SelectedIndex = CInt(index)
End Function

Public Sub ShowIndexed(ByRef xpc As xpCombo)
    Dim index As Integer
    Dim hwnd As Long
    hwnd = XPCIndexer.GetHwndOfXPComboLB(xpc)
    index = SelectedIndex(hwnd)
    xpc.Text = xpc.List(index)
End Sub
0
 
GPrentice00Commented:
Or, use the listindex property in its Set mode to have the same result.  Probably better actually...

as in...

Public Sub ShowIndexed(ByRef xpc As xpCombo)
    Dim index As Integer
    Dim hwnd As Long
    hwnd = XPCIndexer.GetHwndOfXPComboLB(xpc)
    index = SelectedIndex(hwnd)

    xpc.ListIndex = index

End Sub

0
 
jgarthAuthor Commented:
GPrentice As the commercial says "Brilliant Just Brilliant"!

Increased points to 400 because this was just way more work than I ever imagined.
Thank you very much for all the time and Grey matter that you put in.

Oh BTW you might want to post this solution on there forum, I saw a post by someone in English asking the same question and the Someone posted back saying that it does not work with a regular VB Combo control so basicaly don't expect it to work with CoolXp Combo.  I realised the guy was full of crap because I use tons of VB Combo's in this mode and the index works perfectly.

Thanks Again.
0
 
GPrentice00Commented:
You are very welcome, and I am glad that I contributed to your not having to undo piles of code.
Thanks for the points, esp for boosting them.
I will consider your suggestion, maybe take some time to clean it up more first if possible, but definitely if someone said it can't be done, thats reason enough to show a solution.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now