Page 1 of 1
MultiColumn Combobox data
Posted: 10 Jan 2013, 16:19
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?
Re: MultiColumn Combobox data
Posted: 11 Jan 2013, 10:06
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.
Re: MultiColumn Combobox data
Posted: 13 Jan 2013, 00:52
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.
Re: MultiColumn Combobox data
Posted: 14 Jan 2013, 11:51
by engee30
Sorry for my poor explanation to the problem.
Anyways, you got me right. That's precisely what I wanted to get. Thanks again, TiKu.
Re: MultiColumn Combobox data
Posted: 03 Feb 2013, 00:33
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
Re: MultiColumn Combobox data
Posted: 03 Feb 2013, 02:14
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:
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
Re: MultiColumn Combobox data
Posted: 04 Feb 2013, 11:41
by engee30
Thank you, TiKu. That did the trick.
Kind regards,
Pete
Re: MultiColumn Combobox data
Posted: 09 Feb 2013, 15:16
by engee30
Hi
Is it possible to keep open the DropDownWindow of the Combobox after clicking an item in the DropDown list?
Regards,
Pete
Re: MultiColumn Combobox data
Posted: 09 Feb 2013, 17:07
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
Re: MultiColumn Combobox data
Posted: 11 Feb 2013, 23:58
by engee30
Hi TiKu. Oh yes, that subclassing bit of coding did the job. Thanks again.
Kind Regards,
Pete