By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,595 Members | 3,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,595 IT Pros & Developers. It's quick & easy.

multi column combo box in vb.net

P: n/a
Hi

Does anyone know how to create a multi column combo box from the same table?

Thanks,
Cindy
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Do you have a control that displays multi columns right now? If so post the
code to create the columns and the code that populates the datasource

"CindyH" <no**@none.com> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
Hi

Does anyone know how to create a multi column combo box from the same
table?

Thanks,
Cindy

Nov 21 '05 #2

P: n/a
No, what I really want is a combo box that is multi colum and autoformat.
I found an example of an autoformat, which is working well and now I need
the multi column part.
I have a customerID, lastname and firstname columns from same table
(dataset) that I would like to display, searching by last name.

This is the code I'm using for the autoformat:

It is in a module and I'm calling through the keyup event for the combobox.
---------------------------
Private Sub CboLastName_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles CboLastName.KeyUp

AutoComplete(CboLastName, e)

End Sub

----------------------------------------------------------------------------

Module Module1

Public Sub AutoComplete(ByVal cbo As ComboBox, _

ByVal e As System.Windows.Forms.KeyEventArgs)

' Call this from your form passing in the name

' of your combobox and the event arg:

' AutoComplete(cboState, e)

Dim iIndex As Integer

Dim sActual As String

Dim sFound As String

Dim bMatchFound As Boolean

'check if the text is blank or not, if not then only proceed

If Not cbo.Text = "" Then 'if the text is not blank then only proceed

' If backspace then remove the last character

' that was typed in and try to find

' a match. note that the selected text from the

' last character typed in to the

' end of the combo text field will also be deleted.

If e.KeyCode = Keys.Back Then

cbo.Text = Mid(cbo.Text, 1, Len(cbo.Text) - 1)

End If

' Do nothing for some keys such as navigation keys...

If ((e.KeyCode = Keys.Left) Or _

(e.KeyCode = Keys.Right) Or _

(e.KeyCode = Keys.Up) Or _

(e.KeyCode = Keys.Down) Or _

(e.KeyCode = Keys.PageUp) Or _

(e.KeyCode = Keys.PageDown) Or _

(e.KeyCode = Keys.Home) Or _

(e.KeyCode = Keys.End)) Then

Return

End If

Do

' Store the actual text that has been typed.

sActual = cbo.Text

' Find the first match for the typed value.

iIndex = cbo.FindString(sActual)

' Get the text of the first match.

' if index > -1 then a match was found.

If (iIndex > -1) Then '** FOUND SECTION **

sFound = cbo.Items(iIndex).ToString()

' Select this item from the list.

cbo.SelectedIndex = iIndex

' Select the portion of the text that was automatically

' added so that additional typing will replace it.

cbo.SelectionStart = sActual.Length

cbo.SelectionLength = sFound.Length

bMatchFound = True

Else '** NOT FOUND SECTION **

'if there isn't a match and the text typed in is only 1 character

'or nothing then just select the first entry in the combo box.

If sActual.Length = 1 Or sActual.Length = 0 Then

' cbo.SelectedIndex = 0

' cbo.SelectionStart = 0

' cbo.SelectionLength = Len(cbo.Text)

' bMatchFound = True

MsgBox("Not Found")

bMatchFound = True

Else

'if there isn't a match for the text typed in then

'remove the last character of the text typed in

'and try to find a match.

'************************** NOTE **************************

'COMMENT THE FOLLOWING THREE LINES AND UNCOMMENT

'THE (bMatchFound = True) LINE

'INCASE YOU WANT TO ALLOW TEXTS TO BE TYPED IN

' WHICH ARE NOT IN THE LIST. ELSE IF

'YOU WANT TO RESTRICT THE USER TO TYPE TEXTS WHICH ARE

'NOT IN THE LIST THEN LEAVE THE FOLLOWING THREE LINES AS IT IS

'AND COMMENT THE (bMatchFound = True) LINE.

'************************************************* **********

'/////// THREE LINES SECTION STARTS HERE ///////////

cbo.SelectionStart = sActual.Length - 1

cbo.SelectionLength = sActual.Length - 1

cbo.Text = Mid(cbo.Text, 1, Len(cbo.Text) - 1)

' MsgBox("Not Found")

'/////// THREE LINES SECTION ENDS HERE /////////////

' bMatchFound = True

End If

End If

Loop Until bMatchFound

End If

End Sub

End Module

"Chris" <cc*********@hotmail.com> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
Do you have a control that displays multi columns right now? If so post the code to create the columns and the code that populates the datasource

"CindyH" <no**@none.com> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl...
Hi

Does anyone know how to create a multi column combo box from the same
table?

Thanks,
Cindy


Nov 21 '05 #3

P: n/a
Cindy,

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

The only thing I did with is was looking at it,

I hope this helps,

Cor
Nov 21 '05 #4

P: n/a
"CindyH" <no**@none.com>'s wild thoughts were released on
Wed, 31 Aug 2005 16:14:49 -0500 bearing the following fruit:
Hi

Does anyone know how to create a multi column combo box from the same table?


Have you considered creating a usercontrol that inherits
from the combo box. You could then replace the drop down
with a control of your choice.

Jan Hyde (VB MVP)

--
Did you ever date a witch? Yes, but just for a spell. (Bob Thaves)

[Abolish the TV Licence - http://www.tvlicensing.biz/]

Nov 21 '05 #5

P: n/a
Hey, thanks - this looks like what I am looking for!
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Cindy,

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

The only thing I did with is was looking at it,

I hope this helps,

Cor

Nov 21 '05 #6

P: n/a
Thanks i gt so many funtionally in one control,i hop in future i can
also help ....,whn i gt core knowldge ..bt its never ending process :-)
Cindy H wrote:
Hey, thanks - this looks like what I am looking for!
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Cindy,

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

The only thing I did with is was looking at it,

I hope this helps,

Cor


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.