MultiColumn Combobox data

The place for threads about TimoSoft ComboListBoxControls
Post Reply
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

MultiColumn Combobox data

Post by engee30 »

Hello

Let's say I've got a Multicolumn Combobox of 3 columns already populated with some text. Each Combobox item has strings under Text, Column 1 and Column 2. I know how to retrieve the Comboitem text eg by:

Code: Select all

Debug.Print cmbColumns.ComboItems(10).Text
But I can't find a similar way to get the strings stored under each of the columns for each Comboitem. :?:
What to do to get access to such data?
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: MultiColumn Combobox data

Post by TiKu »

I'm not at home until sunday and don't remember how I've implemented the MultiColumn sample. I'll give you a reply on sunday.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: MultiColumn Combobox data

Post by TiKu »

I'm not sure whether I understood your question correctly. The following code takes a ComboBoxItem object (myComboItem) and retrieves its text for the 2nd and 3rd column:

Code: Select all

  Dim tagObject As Object

  Set tagObject = GetComboTag(myComboItem)
  If Not (tagObject Is Nothing) Then
    If TypeOf tagObject Is CMultiColumnItem Then
      Debug.Print tagObject.Text(2), tagObject.Text(3)
    End If
  End If
In production code, I would put this code into a function that takes a ComboBoxItem object and a column index and returns the text as String.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: MultiColumn Combobox data

Post by engee30 »

Sorry for my poor explanation to the problem. :oops:
Anyways, you got me right. That's precisely what I wanted to get. Thanks again, TiKu.

:)
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: MultiColumn Combobox data

Post by engee30 »

Hello

This time I've got a problem changing default colours of the Multicolumn Combo. I'd like to have BackColor & ListBackColor in Black, and ForeColor & ListForeColor in White. I've changed the properties in the Properties Window, but it doesn't seem to work and have any effect. What am I doing wrong, or maybe I'm missing something? :|
Pete
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: MultiColumn Combobox data

Post by TiKu »

Add this declaration to the CMultiColumnItem class:

Code: Select all

  Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Add this variable to the CMultiColumnItem.OwnerDrawItem method:

Code: Select all

Dim hBrush As Long
In this method replace the following code

Code: Select all

    If itemState And OwnerDrawItemStateConstants.odisSelected Then
      If itemState And OwnerDrawItemStateConstants.odisFocus Then
        newBkColor = COLOR_HIGHLIGHT
        newLineColor = COLOR_3DSHADOW
        newTextColor = COLOR_HIGHLIGHTTEXT
      Else
        newBkColor = COLOR_3DFACE
        newLineColor = COLOR_3DSHADOW
        newTextColor = COLOR_BTNTEXT
      End If
    Else
      newBkColor = COLOR_WINDOW
      newLineColor = COLOR_3DSHADOW
      newTextColor = COLOR_WINDOWTEXT
    End If

    ' draw item background
    Call FillRect(hDC, rcItem, GetSysColorBrush(newBkColor))

    ' draw the columns
    hPen = CreatePen(PS_SOLID, 1, GetSysColor(newLineColor))
    If hPen Then
      hPreviousPen = SelectObject(hDC, hPen)
      oldTextColor = SetTextColor(hDC, GetSysColor(newTextColor))
with

Code: Select all

    If itemState And OwnerDrawItemStateConstants.odisSelected Then
      If itemState And OwnerDrawItemStateConstants.odisFocus Then
        newBkColor = GetSysColor(COLOR_HIGHLIGHT)
        newLineColor = GetSysColor(COLOR_3DSHADOW)
        newTextColor = GetSysColor(COLOR_HIGHLIGHTTEXT)
      Else
        newBkColor = GetSysColor(COLOR_3DFACE)
        newLineColor = GetSysColor(COLOR_3DSHADOW)
        newTextColor = GetSysColor(COLOR_BTNTEXT)
      End If
    Else
      newBkColor = vbBlack 'GetSysColor(COLOR_WINDOW)
      newLineColor = GetSysColor(COLOR_3DSHADOW)
      newTextColor = vbWhite 'GetSysColor(COLOR_WINDOWTEXT)
    End If

    ' draw item background
    hBrush = CreateSolidBrush(newBkColor)
    Call FillRect(hDC, rcItem, hBrush)
    Call DeleteObject(hBrush)

    ' draw the columns
    hPen = CreatePen(PS_SOLID, 1, newLineColor)
    If hPen Then
      hPreviousPen = SelectObject(hDC, hPen)
      oldTextColor = SetTextColor(hDC, newTextColor)
Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: MultiColumn Combobox data

Post by engee30 »

Thank you, TiKu. That did the trick. :)
Kind regards,
Pete
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: MultiColumn Combobox data

Post by engee30 »

Hi

Is it possible to keep open the DropDownWindow of the Combobox after clicking an item in the DropDown list?
Regards,
Pete
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: MultiColumn Combobox data

Post by TiKu »

It can be done using subclassing. In the ListDropDown event, subclass the cmbColumns.hWndListBox window and in the ListCloseUp event unsubclass it. In the message handling function, handle the WM_LBUTTONUP message and make sure that it does not get forwarded to the original message handling function:

Code: Select all

Const WM_LBUTTONUP = &H202
...
Select Case uMsg
  Case WM_LBUTTONUP
    bCallDefProc = False
End Select
...
The code is for usage with my subclassing framework (which is being used by e.g. the Events sample). The line "bCallDefProc = False" tells it to "eat" this message, i.e. to not call DefSubclassProc for it. DefSubclassProc forwards messages to the original message handler.

/EDIT: However, this will not disable the possibility to close the drop-down using the keyboard. For this you'll also have to handle WM_KEYDOWN or WM_KEYUP (I'm not quite sure which one) and "eat" it as well.

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
engee30
Lt. Commander
Posts: 54
Joined: 25 Sep 2012, 19:49
Location: Swindon, UK
Contact:

Re: MultiColumn Combobox data

Post by engee30 »

Hi TiKu. Oh yes, that subclassing bit of coding did the job. Thanks again. :)
Kind Regards,
Pete
Post Reply