944,134 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 31619
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 26th, 2007
0

Multi column combo box

Expand Post »
Hello there: This is my issue. I do have one combo box in a form from which I want to select a person, by selecting the ID. In the combo box I want to show sorted name, last name, and date of birth. I wonder this should not be so difficult, but I have no idea about how to do so. Could please anybody out there give me a hand!?
Thanks
Luisofo
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
luisofo is offline Offline
4 posts
since Feb 2007
Feb 26th, 2007
0

Re: Multi column combo box

>In the combo box I want to show sorted name, last name, and date of birth

If you have three things to display you'll be better off using listView instead of a combo box.


To sort by different data types you have to use Icomparator.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 27th, 2007
0

Re: Multi column combo box

I think I probably was not clear enough. I want to have in the combo box 4 columns: Name, Last name, Born date, and the ID of the person. But normally combo boxes only allow you 2 columns, one for the value to show and other for the value to store. I want to find the way to show all the 4 columns and selecting the one that I do need.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
luisofo is offline Offline
4 posts
since Feb 2007
Feb 27th, 2007
0

Re: Multi column combo box

Incorrect.

Combo box = one column

http://www.startvbdotnet.com/controls/combo.aspx

You prolly mean, listView or DataGridView. Can you post a picture to better explain what you mean?
Last edited by iamthwee; Feb 27th, 2007 at 2:20 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 1st, 2007
0

Re: Multi column combo box

I'm not sure I understand exactly what you're doing, but I think I have an idea.
What would probably be best for you to use would be a DataGrid. ESPECIALLY if the data you're populating the fields with is db driven. It would be relatively easy to set up as well.
The article I posted below describes EXACTLY what you need to do to setup a datagrid.
I hope this was helpful.
Good Luck.
http://www.devcity.net/Articles/215/1/article.aspx
Reputation Points: 14
Solved Threads: 0
Newbie Poster
mercury049 is offline Offline
6 posts
since Nov 2006
Mar 1st, 2007
0

Re: Multi column combo box

i can tell you how to do this in access if thats any help?
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
Mar 1st, 2007
0

Re: Multi column combo box

Actually in ACCESS it is a very simple thing to do. But I am coding now in .NET, so as you know there the things are different.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
luisofo is offline Offline
4 posts
since Feb 2007
Mar 17th, 2007
0

Re: Multi column combo box

I am also facing the same problem .
i have fetched data from data in a data grid but i dont know how to fetch data from database in a combo in multi columns. please inform me also whenever you got the solution.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
FaridMasood is offline Offline
59 posts
since Mar 2007
Apr 16th, 2008
0

Re: Multi column combo box

Click to Expand / Collapse  Quote originally posted by luisofo ...
Hello there: This is my issue. I do have one combo box in a form from which I want to select a person, by selecting the ID. In the combo box I want to show sorted name, last name, and date of birth. I wonder this should not be so difficult, but I have no idea about how to do so. Could please anybody out there give me a hand!?
Thanks
Luisofo

-----------------------
I have the same problem. Have you found the solution? Hope you have.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sacretheart is offline Offline
1 posts
since Apr 2008
Apr 30th, 2008
0

Re: Multi column combo box

class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none">'Courier New'">Imports System.Drawing.Drawing2D

Imports System.Windows

Public Class MultiColumnCombo

Inherits System.Windows.Forms.ComboBox

Private _ColumnWidths As String = "100"

Private _ColumnWidthsArray As String()

Private _DoNotReact As Boolean = False

Private _Textchanged As Boolean = False

Sub New()

MyBase.New()

MyBase.DrawMode = DrawMode.OwnerDrawFixed

'SetStyle(ControlStyles.UserPaint, True)

'SetStyle(ControlStyles.AllPaintingInWmPaint, True)

'SetStyle(ControlStyles.DoubleBuffer, True)

End Sub





Public Property ColumnWidths() As String

Get

Return _ColumnWidths

End Get

Set(ByVal Value As String)

_ColumnWidths = Value

_ColumnWidthsArray = Value.Split(CType(";", Char))

Dim w As Integer = 0

For Each str As String In _ColumnWidthsArray

w += CInt(str)

Next str

MyBase.DropDownWidth = w + 10

End Set

End Property



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

' Set the DrawMode property to draw fixed sized items.



'

'If _Textchanged Then

' _Textchanged = False

' Exit Sub

'End If



Dim myBrush As Brush

'If e.Bounds.Y = 0 Then

' ItemHeight = 32

'Else

' ItemHeight = 16

'End If

' e.DrawBackground()

Dim LightColor As Color = Color.Blue

Dim DarkColor As Color = Color.Black

Dim GradBrush As Brush = New LinearGradientBrush(e.Bounds, LightColor, DarkColor, LinearGradientMode.Vertical)







Select Case CInt((e.State And DrawItemState.Selected))

'Case DrawItemState.Selected + DrawItemState.NoAccelerator + DrawItemState.NoFocusRect, DrawItemState.Selected

Case DrawItemState.Selected

myBrush = New SolidBrush(BackColor)

e.Graphics.FillRectangle(GradBrush, e.Bounds)

Case Else

myBrush = New SolidBrush(ForeColor)

'myBrush = GradBrush

e.Graphics.FillRectangle(New SolidBrush(BackColor), e.Bounds)

End Select







Dim str As String

' Draw the current item text based on the current Font and the custom brush settings.

Dim row As DataRowView = (CType(MyBase.Items(e.Index), DataRowView))

Dim newpos As Integer = e.Bounds.X

Dim endpos As Integer = e.Bounds.X



For indx As Integer = 0 To UBound(_ColumnWidthsArray)

Dim ColLength As Integer = CType(_ColumnWidthsArray(indx), Integer)

endpos += ColLength



Dim Charaant As Integer = CInt(Math.Round(CDbl(ColLength) / 6.2))

Dim rawitem As String = row.Item(indx).ToString()



If ColLength <> 0 Then





If Charaant > rawitem.Length Then

str = rawitem



Else



str = rawitem.Substring(0, Charaant)

End If



Dim r As RectangleF = New RectangleF(newpos + 2, e.Bounds.Y, endpos - 1, e.Bounds.Height)



'e.Graphics.FillRectangle(myBrush, r)



e.Graphics.DrawString(str, e.Font, myBrush, r)



'ControlPaint.DrawBorder3D(e.Graphics, New Rectangle(endpos + 2, e.Bounds.Y, newpos, e.Bounds.Height))

'e.Graphics.DrawString("mycol", e.Font, myBrush, New RectangleF(newpos, 0, CInt(_ColumnWidthsArray(indx)), ItemHeight))

If indx <= UBound(_ColumnWidthsArray) Then

e.Graphics.DrawLine(New Pen(Color.Black), endpos, e.Bounds.Y, endpos, Me.ItemHeight * Me.MaxDropDownItems)

e.Graphics.DrawLine(New Pen(Color.LightGray), endpos + 1, e.Bounds.Y, endpos + 1, Me.ItemHeight * Me.MaxDropDownItems)

End If

End If



newpos = endpos

Next

' e.DrawFocusRectangle()

myBrush.Dispose()

GradBrush.Dispose()





End Sub



Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)



Dim foundIndex As Integer, textlngth As Integer

If _DoNotReact = False Then

If Me.AccessibilityObject.Value Is Nothing Then

textlngth = 0

Exit Sub

Else

textlngth = Me.AccessibilityObject.Value.Length

End If



If textlngth = 0 Then

MyBase.OnTextChanged(e)

_DoNotReact = False

_Textchanged = False

Exit Sub

End If



If textlngth <> 0 Then



_DoNotReact = True

foundIndex = FindString(Me.AccessibilityObject.Value)

If foundIndex > -1 Then

Me.SelectedIndex = foundIndex

Me.Select(textlngth, Me.Text.Length - textlngth)

'Me.SelectionStart = textlngth

_Textchanged = True

Else

_Textchanged = False

End If

_DoNotReact = False

End If

MyBase.OnTextChanged(e)

End If

_DoNotReact = False







End Sub



Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)

Select Case e.KeyCode

Case Keys.Back, Keys.Enter, Keys.Delete

_DoNotReact = True

Case Keys.Down

Me.DroppedDown = True

Invalidate()



End Select



MyBase.OnKeyDown(e)



End Sub





End Class
Reputation Points: 10
Solved Threads: 0
Newbie Poster
microdeveloper is offline Offline
3 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: A Very very Simple Program
Next Thread in VB.NET Forum Timeline: set TextBoxes equal to zero





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC