Multi column combo box

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 4
Reputation: luisofo is an unknown quantity at this point 
Solved Threads: 0
luisofo luisofo is offline Offline
Newbie Poster

Multi column combo box

 
0
  #1
Feb 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Multi column combo box

 
0
  #2
Feb 26th, 2007
>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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 4
Reputation: luisofo is an unknown quantity at this point 
Solved Threads: 0
luisofo luisofo is offline Offline
Newbie Poster

Re: Multi column combo box

 
0
  #3
Feb 27th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Multi column combo box

 
0
  #4
Feb 27th, 2007
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 6
Reputation: mercury049 is an unknown quantity at this point 
Solved Threads: 0
mercury049's Avatar
mercury049 mercury049 is offline Offline
Newbie Poster

Re: Multi column combo box

 
0
  #5
Mar 1st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,176
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 532
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Multi column combo box

 
0
  #6
Mar 1st, 2007
i can tell you how to do this in access if thats any help?
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 4
Reputation: luisofo is an unknown quantity at this point 
Solved Threads: 0
luisofo luisofo is offline Offline
Newbie Poster

Re: Multi column combo box

 
0
  #7
Mar 1st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 59
Reputation: FaridMasood is an unknown quantity at this point 
Solved Threads: 0
FaridMasood's Avatar
FaridMasood FaridMasood is offline Offline
Junior Poster in Training

Re: Multi column combo box

 
0
  #8
Mar 17th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1
Reputation: sacretheart is an unknown quantity at this point 
Solved Threads: 0
sacretheart sacretheart is offline Offline
Newbie Poster

Re: Multi column combo box

 
0
  #9
Apr 16th, 2008
Originally Posted by luisofo View 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

-----------------------
I have the same problem. Have you found the solution? Hope you have.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 3
Reputation: microdeveloper is an unknown quantity at this point 
Solved Threads: 0
microdeveloper microdeveloper is offline Offline
Newbie Poster

Re: Multi column combo box

 
0
  #10
Apr 30th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC