Why wont this work with a structure and combo box
Public Structure myStructure
Public Name As String
Public Title As String
End Structure
Dim arList As New ArrayList
Dim i As Integer
For i = 0 To 10
Dim ms As New myStructure
ms.Name = "Name " & i.ToString
ms.Title = "Title " & i.ToString
arList.Add(ms)
Next
'
With cmboMyTest
.DisplayMember = "Name"
.ValueMember = "Title"
.DataSource = arList
End With
When I run this, the combo box is filled with the fully qualified name
of the form and "+myStructure"
That is: "ObjectIntro.FormSecondTest+myStructure" is displayed in the
10 items of the combo box.
Thanks for all the help, always.
John
On Mon, 21 Mar 2005 00:45:28 +0100, "Herfried K. Wagner [MVP]"
<hirf-spam-me-(E-Mail Removed)> wrote:
>"Michael C#" <(E-Mail Removed)> schrieb:
>>>> I'm binding a Combobox to an Arraylist, and I'd like to set the
>>>> ValueMember and DisplayMember properties of the Combobox. Is this
>>>> possible
>>>
>>> Yes.
>>>
>>
>> Well as long as it's possible.
>
>???
>
>Sample:
>
>\\\
>Private Sub Form1_Load( _
> ByVal sender As Object, _
> ByVal e As EventArgs _
>) Handles MyBase.Load
> Dim al As New ArrayList
> For i As Integer = 1 To 20
> Dim p As New Person
> p.Name = "Name " & CStr(i)
> p.Age = 70 - i
> al.Add(p)
> Next i
> With Me.ListBox1
> .DisplayMember = "Name"
> .ValueMember = "Age"
> .DataSource = al
> End With
>End Sub
>
>Private Sub ListBox1_SelectedIndexChanged( _
> ByVal sender As Object, _
> ByVal e As EventArgs _
>) Handles ListBox1.SelectedIndexChanged
> MsgBox("Selected value: " & CStr(Me.ListBox1.SelectedValue))
>End Sub
>.
>.
>.
>Public Class Person
> Private m_Name As String
> Private m_Age As Integer
>
> Public Property Name() As String
> Get
> Return m_Name
> End Get
> Set(ByVal Value As String)
> m_Name = Value
> End Set
> End Property
>
> Public Property Age() As Integer
> Get
> Return m_Age
> End Get
> Set(ByVal Value As Integer)
> m_Age = Value
> End Set
> End Property
>
> Public Overrides Function ToString() As String
> Return Me.Name & " (" & Me.Age.ToString() & ")"
> End Function
>End Class
>///
|