[SOLVED] Multi Column Combobox?
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=17099
Printed Date: 27 November 2024 at 4:02am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: [SOLVED] Multi Column Combobox?
Posted By: Xander75
Subject: [SOLVED] Multi Column Combobox?
Date Posted: 11 August 2010 at 4:43am
Hi,
I have had a look into the Codejock Controls and I am aware that the combobox does not support multiple columns
This has always been a major issue with Visual Basic 6, I am aware however that using the "Microsoft Forms 2.0 Obkect Library" does allow this functionality however when used in combination with the Codejock SkinFrameWork the control does not skin!
Is there anyway of having a multiple column combobox in Visual Basic 6 that is skins correctly? If not, then I think this is a major must have to be added to the Codejock Combobox control.
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Replies:
Posted By: jpbro
Date Posted: 11 August 2010 at 9:27am
If you just need a drop-down list style combobox, then you can achieve a multi-column display using Markup.
Try this with a CJ ComboBox on a form:
Private Sub Form_Load() Dim i As Long
With Me.ComboBox1 .Style = xtpComboDropDownList .EnableMarkup = True For i = 0 To 25 .AddItem Chr$(65 + i) .MarkupList(.NewIndex) = "<Grid><Grid.ColumnDefinitions><ColumnDefinition Width='50'/><ColumnDefinition Width='100'/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition/></Grid.RowDefinitions>" & _ "<TextBlock>" & .List(i) & "</TextBlock>" & _ "<TextBlock Grid.Column='2'>Column 2</TextBlock></Grid>" Next i End With End Sub
|
This will give you a 2 column combobox. You use AddItem as you normally would to populate the list, and then use the MarkupList property to add your 2 column markup for each item.
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: Xander75
Date Posted: 11 August 2010 at 10:21am
Thanks for that jpbro!!!
It's so simple to use from your demo code.
Can I ask one other question, do you know how to change the dropdown list width automatically to the longest row in the list?
I can manually manipulate the width using the DropDownWidth method but it would be nice to have this autosize the list width if possible.
If not it's no big loss as the multiple column was what I was really looking for.
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: jpbro
Date Posted: 11 August 2010 at 10:34am
Glad to help. Unfortunately, I'm not aware of a way to determine the width of the longest row. One thing you could do, is set the width of the grid to the width of the ComboBox less the button/scrollbar width, and then set the TextWrapping property of your TextBlocks to Wrap.
This would all of the text in the drop-down list portion (and it would fit to the combobox width). The only drawback is that you would only see the first line of the text in the edit portion of the combobox.
Try this:
Private Sub Form_Load() Dim i As Long
With Me.ComboBox1 .Style = xtpComboDropDownList .EnableMarkup = True For i = 0 To 25 .AddItem Chr$(65 + i) .MarkupList(.NewIndex) = "<Grid Width='" & Me.ComboBox1.Width / Screen.TwipsPerPixelX - 24 & "'><Grid.ColumnDefinitions><ColumnDefinition Width='50'/><ColumnDefinition Width='*'/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition/></Grid.RowDefinitions>" & _ "<TextBlock TextWrapping='Wrap'>" & .List(i) & "</TextBlock>" & _ "<TextBlock TextWrapping='Wrap' Grid.Column='2'>Column 2 Column 2 Column 2 Column 2 Column 2 Column 2 Column 2</TextBlock></Grid>" Next i End With End Sub
|
In that sample, I use a fixed 24px to account for the button/vertical scrollbar, but you should use GetSystemMetrics API to get the actual value. I also used * for the width of the last column to tell it to use the available remaining width for that column. TextWrapping='Wrap' wraps the text at the cell edge.
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: Xander75
Date Posted: 11 August 2010 at 10:49am
Hi,
Thanks again for the info, I will check it out however I am just glad that the CJ Combo can display multiple columns.
I have tried the following code as a requirement of my projects is to use several Combo's as filters. But instead of loading the text directly I need to do this on focus of the control as for example in the screenshot I have attached I would require to filter down the Products based on the selected Brand.
However the following code fails to display the dropdown list. Any ideas?
Private Sub ComboBox1_GotFocus() With Me.ComboBox1 .AutoComplete = True .Clear .DropDownWidth = 8500 .EnableMarkup = True
For i = 0 To 25 .AddItem Chr$(65 + i) .MarkupList(.NewIndex) = "<Grid>" & _ " <Grid.ColumnDefinitions>" & _ " <ColumnDefinition Width='50'/>" & _ " <ColumnDefinition Width='200'/>" & _ " </Grid.ColumnDefinitions>" & _ " <Grid.RowDefinitions>" & _ " <RowDefinition/>" & _ " </Grid.RowDefinitions>" & _ " <TextBlock>" & .List(i) & "</TextBlock>" & _ " <TextBlock Grid.Column='2'>Col 2 sdf sdf sdf sdf : " & i & "</TextBlock>" & _ "</Grid>" Next
.DroppedState = True End With End Sub
|
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: Xander75
Date Posted: 11 August 2010 at 11:07am
Hi,
I have resolved the dropdown list issue, it was caused with setting both the EnableMarkup and DroppedState to true in the GotFocus event.
Setting the combo to EnableMarkup in the form load event resolved the issue.
Private Sub ComboBox1_GotFocus()
With Me.ComboBox1
.AutoComplete = True .Clear .DropDownWidth = 8500
For i = 0 To 25 .AddItem Chr$(65 + i) .MarkupList(.NewIndex) = "<Grid>" & _ " <Grid.ColumnDefinitions>" & _ " <ColumnDefinition Width='50'/>" & _ " <ColumnDefinition Width='200'/>" & _ " </Grid.ColumnDefinitions>" & _ " <Grid.RowDefinitions>" & _ " <RowDefinition/>" & _ " </Grid.RowDefinitions>" & _ " <TextBlock>" & .List(i) & "</TextBlock>" & _ " <TextBlock Grid.Column='2'>Col 2 sdf sdf sdf sdf : " & i & "</TextBlock>" & _ "</Grid>" Next .DroppedState = True
End With
End Sub
Private Sub Form_Load() ComboBox1.EnableMarkup = True End Sub
|
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
|