473,503 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple columns in Combobox list

I am using Visual Studio 2003.
In the standard combobox control it would appear that only 1 column of data
can be displayed in the list (as stipulated in the DisplayMember property).
In VBA it was always possible to specify a column count and then set the
width for each column (setting 0 width for columns not to be displayed). The
Bound Column property was then specified to set the data to be retrieved from
the control (the ValueMember property being the equivalent).
I would like to display 2 columns of data in the list to make it easier for
the user to select the correct data (ID and description). Once the selection
is made then only the ID is shown in the control text.
I can't see how to do this in VS 2003. Does anybody have any suggestions?

Jan 9 '06 #1
5 30010
"Keith G" <Ke****@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
I am using Visual Studio 2003.
In the standard combobox control it would appear that only 1 column of
data
can be displayed in the list (as stipulated in the DisplayMember
property).
In VBA it was always possible to specify a column count and then set the
width for each column (setting 0 width for columns not to be displayed).
The
Bound Column property was then specified to set the data to be retrieved
from
the control (the ValueMember property being the equivalent).
I would like to display 2 columns of data in the list to make it easier
for
the user to select the correct data (ID and description). Once the
selection
is made then only the ID is shown in the control text.
I can't see how to do this in VS 2003. Does anybody have any suggestions?


Looks like there's still nothing "built in" but......

This page....

Visual Basic Frequently Asked Questions
http://blogs.msdn.com/vbfaq/archive/...28/121869.aspx

.....leads to an excellent resource...

vbAccelerator IconComboBox Control
http://www.vbaccelerator.com/home/NE...ox/article.asp

I've never tried anything "dotNet" from vbAccelerator but his VB5/6 stuff is
top notch (it's very important to read his instructions carefully)

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Jan 9 '06 #2
Keith,

I don't know if it is the same as from Ken, I got the idea from not. It
seems to be excelent (I only tried it once).

http://www.planet-source-code.com/vb...2934&lngWId=10

I hope this helps,

Cor
Jan 10 '06 #3
Hi Keith,

In .NET is easy to paint the combobox items yourself, so you can make a
multicolumn combobox with this code:

Friend Class MultiColumnComboBox
Inherits ComboBox

Private m_chFieldSeparator As Char

Friend Sub New()

Me.DrawMode = DrawMode.OwnerDrawFixed
m_chFieldSeparator = ","c

End Sub

Protected Overrides Sub OnDrawItem(ByVal e As
System.Windows.Forms.DrawItemEventArgs)

Dim iXPos As Integer
Dim iYPos As Integer
Dim sText As String
Dim objSizeF As SizeF
Dim sTextPartArray() As String
Dim iTextPartIndex As Integer
Dim sTextPart As String
Dim objBrush As Brush
Dim iMaxLength As Integer

If e.Index >= 0 Then

e.DrawBackground()

sText = Me.Items(e.Index).ToString

sTextPartArray = sText.Split(m_chFieldSeparator)

objBrush = New SolidBrush(e.ForeColor)

iXPos = e.Bounds.X

For iTextPartIndex = 0 To sTextPartArray.Length - 1

sTextPart = sTextPartArray(iTextPartIndex)

objSizeF = e.Graphics.MeasureString(sTextPart, e.Font)

If iTextPartIndex > 0 Then
iMaxLength = GetMaxLength(e.Graphics, e.Font, iTextPartIndex - 1,
m_chFieldSeparator)
Else
iMaxLength = 0
End If

iXPos += iMaxLength
iYPos = e.Bounds.Y

e.Graphics.DrawString(sTextPart, e.Font, objBrush, iXPos, iYPos)

Next

objBrush.Dispose()

Select Case e.State

Case DrawItemState.NoFocusRect

Case Else
e.DrawFocusRectangle()

End Select

Else
MyBase.OnDrawItem(e)
End If

End Sub

Private Function GetMaxLength(ByVal objGraphics As Graphics, ByVal objFont
As Font, ByVal iTextPartIndex As Integer, ByVal chSeparator As Char) As
Integer

Dim iResult As Integer
Dim iIndex As Integer
Dim sTextPartArray() As String
Dim sTextPart As String
Dim sText As String
Dim objSizeF As SizeF
Dim iWidth As Integer

' By default
iResult = 10

For iIndex = 0 To Me.Items.Count - 1

sText = Me.Items(iIndex).ToString

sTextPartArray = sText.Split(chSeparator)

If iTextPartIndex > sTextPartArray.Length - 1 Then
' Out of range
Else

sTextPart = sTextPartArray(iTextPartIndex)

objSizeF = objGraphics.MeasureString(sTextPart, objFont)
iWidth = CType(objSizeF.Width, Integer)

If iWidth > iResult Then
iResult = iWidth
End If

End If

Next

Return iResult

End Function

End Class

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio 2005, Visual Studio .NET,
VB6, VB5 and VBA
You can code, design and document much faster in VB.NET, C#, C++ or VJ#
Free resources for add-in developers:
http://www.mztools.com


"Keith G" <Ke****@discussions.microsoft.com> escribió en el mensaje
news:71**********************************@microsof t.com...
I am using Visual Studio 2003.
In the standard combobox control it would appear that only 1 column of
data
can be displayed in the list (as stipulated in the DisplayMember
property).
In VBA it was always possible to specify a column count and then set the
width for each column (setting 0 width for columns not to be displayed).
The
Bound Column property was then specified to set the data to be retrieved
from
the control (the ValueMember property being the equivalent).
I would like to display 2 columns of data in the list to make it easier
for
the user to select the correct data (ID and description). Once the
selection
is made then only the ID is shown in the control text.
I can't see how to do this in VS 2003. Does anybody have any suggestions?

Jan 10 '06 #4
Thanks Cor,

This is not the same as the ones that Ken suggested.
I agree it is an excelent bit of coding!
It's very easy to configure. The 'LoadingType' property is a nice touch,
being able to change the way the list is loaded (either from a datatable or
combobox item) is very useful.

"Cor Ligthert [MVP]" wrote:
Keith,

I don't know if it is the same as from Ken, I got the idea from not. It
seems to be excelent (I only tried it once).

http://www.planet-source-code.com/vb...2934&lngWId=10

I hope this helps,

Cor

Jan 10 '06 #5
"Keith G" <Ke****@discussions.microsoft.com> schrieb:
In the standard combobox control it would appear that only 1 column of
data
can be displayed in the list (as stipulated in the DisplayMember
property).
In VBA it was always possible to specify a column count and then set the
width for each column (setting 0 width for columns not to be displayed).
The
Bound Column property was then specified to set the data to be retrieved
from
the control (the ValueMember property being the equivalent).
I would like to display 2 columns of data in the list to make it easier
for
the user to select the correct data (ID and description).


Multi Column ComboBox
<URL:http://www.codeproject.com/cs/combobox/multicolumncombo.asp>

Multi-Column ComboBox
<URL:http://www.codeproject.com/vb/net/multicolumncombo.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
17614
by: Therese A. Sorna | last post by:
Hello all... I am using Access 2002, and am trying to find a way for a user to be able to select multiple entries from a drop-down list. I am hoping that given a list as such: a b c d
1
2748
by: Mark | last post by:
My Category and Product tables look like: TblCategory CategoryID Category TblProduct ProductID CategoryID Product
1
2754
by: TheMadHatter | last post by:
I have an array of a custom obj which I am trying to use in multiple comboBoxes without creating multiple copies, but if I put the datasource of the comboboxes to the same array, then at runtime...
1
7040
by: mshenoud | last post by:
I have a comboBox with two columns. I would like to isolate each column so as to compare it to an entry in a table so as to be able to load a yet another form. how can I do that? Details: The...
6
8338
by: fstenoughsnoopy | last post by:
I have a customer order database and I need to pull a customers information, ie first name, last name, address, city, state, zip, phone, etc, into the oder table. i don't know how to go about...
7
3734
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that...
6
5427
by: =?Utf-8?B?UXVhbiBOZ3V5ZW4=?= | last post by:
I am trying to create a generics class with multiple constrains, as follows: public class KeyHandler<Twhere T : TextBoxBase, ComboBox When I try that, the compiler would complain: The class...
2
5103
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for...
0
3146
by: Germaris | last post by:
Hi there! Is it possible to make multiple selections in a ComboBox ? i.e. make n consecutive selections and store them in an array or make n selections in the open list of the CB by using (for...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.