Very good. :))
Note that you can use DataTables as a datasource, also.
[]s
Cesar
"Thief_" <th****@hotmail .com> escreveu na mensagem
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Thanks Ronchese,
I used the following code which does eactly what I need:
Imports System.Windows. Forms
Imports System.Drawing
Imports System.Collecti ons
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.STAThre adAttribute()> _
Public Shared Sub Main()
System.Windows. Forms.Applicati on.Run(New ListBoxSample3( ))
End Sub
Public Sub New()
Me.AutoScaleBas eSize = New Size(5, 13)
Me.ClientSize = New Size(292, 181)
Me.Text = "ListBox Sample3"
ListBox1.Locati on = New Point(24, 16)
ListBox1.Name = "ListBox1"
ListBox1.Size = New Size(232, 130)
textBox1.Locati on = New Point(24, 160)
textBox1.Name = "textBox1"
textBox1.Size = New Size(40, 24)
Me.Controls.Add Range(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(Ne w USState("Washin gton", "WA"))
USStates.Add(Ne w USState("West Virginia", "WV"))
USStates.Add(Ne w USState("Wiscon sin", "WI"))
USStates.Add(Ne w USState("Wyomin g", "WY"))
ListBox1.DataSo urce = USStates
ListBox1.Displa yMember = "LongName"
ListBox1.ValueM ember = "ShortName"
End Sub
Private Sub InitializeCompo nent()
End Sub
Private Sub ListBox1_Select edValueChanged( ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles ListBox1.Select edValueChanged
If ListBox1.Select edIndex <> -1 Then
textBox1.Text = ListBox1.Select edValue
End If
End Sub
End Class
--
|
+-- Thief_
|
"Ronchese" <ro******@smlin fo.com.br> wrote in message
news:eA******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP14.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_
|