473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

More than one column in a Combobox?

Can a combobox conatin more than one column? I want to store text in one
column and in the other (hidden) column store integer values which are
associated with the text.

VB.Net 2003

--
|
+-- Thief_
|
Nov 21 '05 #1
6 3543
I believe there is a property called Value that you can store integers
associated with the Text property.

"Thief_" <th****@hotmail.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
Can a combobox conatin more than one column? I want to store text in one
column and in the other (hidden) column store integer values which are
associated with the text.

VB.Net 2003

--
|
+-- Thief_
|

Nov 21 '05 #2
I think you might be thinking of ASP.NET, because I've never seen a value on
a windows forms combobox, only in ASP.NET

"Terry Olsen" <to******@hotmail.com> wrote in message
news:ON**************@tk2msftngp13.phx.gbl...
I believe there is a property called Value that you can store integers
associated with the Text property.

"Thief_" <th****@hotmail.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
Can a combobox conatin more than one column? I want to store text in one
column and in the other (hidden) column store integer values which are
associated with the text.

VB.Net 2003

--
|
+-- Thief_
|


Nov 21 '05 #3
Look your MSDN Library for DisplayMember and ValueMember properties. There
are samples that explain what you is needing.

[]s
Cesar

"Thief_" <th****@hotmail.com> escreveu na mensagem
news:eK**************@TK2MSFTNGP14.phx.gbl...
Can a combobox conatin more than one column? I want to store text in one
column and in the other (hidden) column store integer values which are
associated with the text.

VB.Net 2003

--
|
+-- Thief_
|

Nov 21 '05 #4
Thief,

In addition to the others. You can use the valuemember and its selected
value.

Be aware that you need for that a datasource. The easiest one is the
datatable however any Ilist implementing array will do that as well with
some more work.

I hope this helps,

Cor
Nov 21 '05 #5
Thanks Ronchese,

I used the following code which does eactly what I need:

Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections

Public Class USState

Private myShortName As String
Private myLongName As String

Public Sub New(ByVal strlongName As String, ByVal strShortName As
String)
MyBase.New()
Me.myShortName = strShortName
Me.myLongName = strLongName
End Sub

Public ReadOnly Property ShortName() As String
Get
Return myShortName
End Get
End Property

Public ReadOnly Property LongName() As String
Get
Return myLongName
End Get
End Property

Public Overrides Function ToString() As String
Return Me.ShortName & " - " & Me.LongName
End Function
End Class
Public Class ListBoxSample3
Inherits Form
Friend WithEvents ListBox1 As ListBox = New ListBox()
Dim textBox1 As TextBox = New TextBox()

<System.STAThreadAttribute()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New ListBoxSample3())
End Sub

Public Sub New()
Me.AutoScaleBaseSize = New Size(5, 13)
Me.ClientSize = New Size(292, 181)
Me.Text = "ListBox Sample3"

ListBox1.Location = New Point(24, 16)
ListBox1.Name = "ListBox1"
ListBox1.Size = New Size(232, 130)
textBox1.Location = New Point(24, 160)
textBox1.Name = "textBox1"
textBox1.Size = New Size(40, 24)
Me.Controls.AddRange(New Control() {ListBox1, textBox1})

' Populates the list box using DataSource.
' DisplayMember is used to display just the long name of each state.
Dim USStates As New ArrayList()
USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))

ListBox1.DataSource = USStates
ListBox1.DisplayMember = "LongName"
ListBox1.ValueMember = "ShortName"

End Sub

Private Sub InitializeComponent()

End Sub

Private Sub ListBox1_SelectedValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
If ListBox1.SelectedIndex <> -1 Then
textBox1.Text = ListBox1.SelectedValue
End If
End Sub
End Class
--
|
+-- Thief_
|

"Ronchese" <ro******@smlinfo.com.br> wrote in message
news:eA**************@TK2MSFTNGP14.phx.gbl...
Look your MSDN Library for DisplayMember and ValueMember properties. There
are samples that explain what you is needing.

[]s
Cesar

"Thief_" <th****@hotmail.com> escreveu na mensagem
news:eK**************@TK2MSFTNGP14.phx.gbl...
Can a combobox conatin more than one column? I want to store text in one
column and in the other (hidden) column store integer values which are
associated with the text.

VB.Net 2003

--
|
+-- Thief_
|

Nov 21 '05 #6
Very good. :))

Note that you can use DataTables as a datasource, also.

[]s
Cesar

"Thief_" <th****@hotmail.com> escreveu na mensagem
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thanks Ronchese,

I used the following code which does eactly what I need:

Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections

Public Class USState

Private myShortName As String
Private myLongName As String

Public Sub New(ByVal strlongName As String, ByVal strShortName As
String)
MyBase.New()
Me.myShortName = strShortName
Me.myLongName = strLongName
End Sub

Public ReadOnly Property ShortName() As String
Get
Return myShortName
End Get
End Property

Public ReadOnly Property LongName() As String
Get
Return myLongName
End Get
End Property

Public Overrides Function ToString() As String
Return Me.ShortName & " - " & Me.LongName
End Function
End Class
Public Class ListBoxSample3
Inherits Form
Friend WithEvents ListBox1 As ListBox = New ListBox()
Dim textBox1 As TextBox = New TextBox()

<System.STAThreadAttribute()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New ListBoxSample3())
End Sub

Public Sub New()
Me.AutoScaleBaseSize = New Size(5, 13)
Me.ClientSize = New Size(292, 181)
Me.Text = "ListBox Sample3"

ListBox1.Location = New Point(24, 16)
ListBox1.Name = "ListBox1"
ListBox1.Size = New Size(232, 130)
textBox1.Location = New Point(24, 160)
textBox1.Name = "textBox1"
textBox1.Size = New Size(40, 24)
Me.Controls.AddRange(New Control() {ListBox1, textBox1})

' Populates the list box using DataSource.
' DisplayMember is used to display just the long name of each state.
Dim USStates As New ArrayList()
USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))

ListBox1.DataSource = USStates
ListBox1.DisplayMember = "LongName"
ListBox1.ValueMember = "ShortName"

End Sub

Private Sub InitializeComponent()

End Sub

Private Sub ListBox1_SelectedValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
If ListBox1.SelectedIndex <> -1 Then
textBox1.Text = ListBox1.SelectedValue
End If
End Sub
End Class
--
|
+-- Thief_
|

"Ronchese" <ro******@smlinfo.com.br> wrote in message
news:eA**************@TK2MSFTNGP14.phx.gbl...
Look your MSDN Library for DisplayMember and ValueMember properties. There
are samples that explain what you is needing.

[]s
Cesar

"Thief_" <th****@hotmail.com> escreveu na mensagem
news:eK**************@TK2MSFTNGP14.phx.gbl...
Can a combobox conatin more than one column? I want to store text in one
column and in the other (hidden) column store integer values which are
associated with the text.

VB.Net 2003

--
|
+-- Thief_
|


Nov 21 '05 #7

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

Similar topics

27
by: DraguVaso | last post by:
Hi, The Multi column comboBox is a well spoken control, that a lot of people desire, and a lot of people buildtheir own. I tested a lot of them, but none really was what i wanted to have. But...
2
by: Arnie | last post by:
I have searched this NG for datasheet column width posts and have read many of them. None of them seem to address what I would like to do. I'm beginning to think what I want can't be done. Here...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
2
by: jaYPee | last post by:
i have search a lot of newsgroup and some website to find a sample for multi column combobox in datagrid but no luck. there are so many sample i found but it is not located in datagrid. i would...
17
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5...
2
by: Mike TI | last post by:
March 26, 2006 Hi All I am new to VB.Net, using VB.Net 2005 Is there a way to have more than one column in a combo box. Thanks
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
1
by: Coll | last post by:
I'm trying to create a combo box using the wizard. It's based on a query with 5 fields - enum, ename, startdate, enddate, and recordnumber. In my query enum is not visible, and that field has...
0
by: marisenthil | last post by:
i am created windows application. i have a gridview in form1 with combobox column. using binding source binded data from the database to gridview except combobox column. i used separate binding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.