MultiColumn ComboBox? - Open for Discussion.

Hi all;

Maybe I am missing something, but given the follow example taken from msdn:

' Declare comboBox1 as a ComboBox.
Friend WithEvents ComboBox1As System.Windows.Forms.ComboBox

' This method initializes the combo box, adding a large string
' array but limiting the drop-down size to six rows so the combo box
' doesn't cover other controls when it expands.
PrivateSub InitializeComboBox()
Me.ComboBox1 =New System.Windows.Forms.ComboBox
Dim employees()AsString =NewString() {"Hamilton, David", _
"Hensien, Kari", "Hammond, Maria", "Harris, Keith", _
"Henshaw, Jeff D.", "Hanson, Mark", "Harnpadoungsataya, Sariya", _
"Harrington, Mark", "Harris, Keith", "Hartwig, Doris", _
"Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", _
"Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", "Henshaw, Jeff D.", _
"Hensien, Kari", "Harris, Keith", "Henshaw, Jeff D.", _
"Hensien, Kari", "Hasselberg, Jonas", "Harrington, Mark", _
"Hedlund, Magnus", "Hay, Jeff", "Heidepriem, Brandon D."}

ComboBox1.Items.AddRange(employees)
Me.ComboBox1.Location =New System.Drawing.Point(136, 32)
Me.ComboBox1.MaxDropDownItems = 5
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size =New System.Drawing.Size(136, 81)
Me.ComboBox1.TabIndex = 0
Me.Controls.Add(Me.ComboBox1)
End Sub

This will display a dropdown list like this:

Hassall, Mark
Hasselberg, Jonas
Harnpadoungsataya, Sariya
Henshaw, Jeff D.
Henshaw, Jeff D.
Hensien, Kari
Harris, Keith
Henshaw, Jeff D.

IMHO, doesn't this look better?

Surname Given Names
Hassall Mark
Hasselberg Jonas
Harnpadoungsataya Sariya
Henshaw Jeff D.
Henshaw Jeff D.
Hensien Kari
Harris Keith
Henshaw Jeff D.
Now given a large company may have a few employees with the same name (ie. Henshaw, Jeff D.) you may need some additional information to determine which Henshaw you want. So lets add the Department they work in (or Employee Id or Phone or WhatEver).
Without MultiColumns:

Hassall, Mark - Shipping
Hasselberg, Jonas - Accounting
Harnpadoungsataya, Sariya - Production
Henshaw, Jeff D. - Shipping
Henshaw, Jeff D. - Accounting
Hensien, Kari - Production
Harris, Keith - Production
Henshaw, Jeff D. - Production

With MultiColumns:

Surname Given Names Department
Hassall Mark Shipping
Hasselberg Jonas Accounting
Harnpadoungsataya Sariya Production
Henshaw Jeff D. Shipping
Henshaw Jeff D. Accounting
Hensien Kari Production
Harris Keith Production
Henshaw Jeff D. Production

A MultiColumn ComboBox would be great! Also for table lookups to show the item's code and item's description.

Or am I missing the boat on this and this senario is better handled in a different way with a different control?

On a side note: I am very impressed that the ComboBox has been implemented onto the DataGridView! HooRay!! Now to get this with a MultiColumn option as well!!Big Smile

[4071 byte] By [ComSpec] at [2008-2-24]
# 1
For MultiColumnComboBox , To use ListView control with detailed mode is good.
you will put the listView control to a winForm.
then u will fire the dropDown event for comboBox. in this event u will call the winForm and u have to send the dataTablo to assing it as datasource to listview.
DogaOztuzun at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
HI,
MultiColumn controls is indeed a very good control that a programmer must have. But sad to say only DataGrid and Listview controls contains multi column properties... though it's very nice that microsoft would provide us with a control like that... Or a package of NEW controls!

Well, I guess Im just wishfull Thinking....
Why wont you try looking for some third party controls? I can remember playing with one (Multicolumn Combo) in my VB Days...

try searching here...
www.componentsource.com
cheers,
Paul June A. Domag

PaulDomag at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Hey Doga & Paul;

I have actually created my own dropdown using the DataGrid. Works great.

But I was really interested in was if you did not create your own MultiColumn dropdown, how does Microsoft imagine you to complete this obvious limitation using only the standard controls?

And why would Microsoft not see the obvious need for such controls as their standard package?

ComSpec at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
yeah MultiColumnCombo control is really usefull. But I dont see it a control to spend money.
Its not hard to make.
I think Microsoft happy about that... There isnt a control like this in .net framework but they use their own custom controls... so they give you a platform to create, to develop. You can do everything with this feature.
Everything is usefull .. it changes. there are really cool grid controls. I want them into .net framework : )
: ) I talked nonsense..
good works
DogaOztuzun at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
Hi all,

I passed your feedback on to the Windows Forms group. I agree this is very nice to have.

If you want extra reinforcement, you could file a suggestion in Product Feedback Center.

I'm also glad to hear you found a workaround with DataGridView. I think using DGV is a great solution in VB 2005. In 2003, I'd use the ListView or a custom control off the shelf.

Best,
Paul Yuknewicz

PaulYuk_MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

Hi,

Can anyone give me the working source code for creating a Multi-Column Combobox in DataGridView in VB.NET.

Thanks!

nkotb at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

Would you please share your source code?

I have been trying to use ASP web code for a multicolumn Combo box with no success

VisualBasicGuruWannabe at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8
Actually it is relative simple to create a Multicolumn ComboBox.

First make a ComboBoxItem class..
Pseudocodce.

Code Snippet

class ComboBoxItem
priavte Col1Value, Col2Value, Col3Value ..... as string

sub new(col1value, optional col2value....)
me.Col1Value = Col1Value
.....
end sub

public overrides function ToString()
' Use first column to display in combobox
return me.Col1Value
end function
end class


Then make a new class that inhertis System.Windows.Forms.ComboBox (?)

Code Snippet

class MultiColCombo
inherits ComboBox

Private WithEvents MyComboBox As System.Windows.Forms.ComboBox

Public Sub New()
MyBase.New()
MyComboBox = Me
End Sub

Protected Overrides Sub OnCreateControl()
Me.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.Invalidate()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then MyBase.Dispose(True)
GC.SuppressFinalize(Me)
End Sub

Private Sub MyComboBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyComboBox.DrawItem
' Look at .net documentation for examples.
' Her you can draw your own dropdown-display...
Rectangle = New Rectangle(e.Bounds.Left, e.Bounds.Top, Me.Col1Width, e.Bounds.Height)
e.Graphics.DrawString(Me.Items(e.Index).Col1Value, Me.Font, New System.Drawing.SolidBrush(ItemTextColor), Rectangle)
and so on....

end sub


This is a bit messy.. But hopefulley it gives you an idea...
jmac82 at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...