Let me preface this by saying that I have several years of VB experience prior to .NET, which I'm rapidly learning doesn't mean squat in the .NET world.
One of the really cool things I see in .NET is the ability to bind a data aware control to just about anything. However, I can't make it work right to save my life.
I don't get any errors, but the control is being populated with the name of the structure I created the BindingList on instead of the contents of the Binding list.
The test code below demonstrates the issue. When the below code runs, listbox1 populates with "one thing" and "another thing" as it should. Listbox2 however populates with "test.Form1+simplestruct" and "test.Form1+simplestruct".
I know the BindingList contains the data because I can access it direclty using "?ctype(binder.Current,simplestruct).someting" from the immidiate window while paused and it returns "one thing".
What the heck am I doing wrong??
Steve Z
Public Structure simplestruct
Dim someting As String
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mylist As New System.ComponentModel.BindingList(Of simplestruct)
Dim tmpstruct As New simplestruct
tmpstruct.someting = "one thing"
mylist.Add(tmpstruct)
tmpstruct.someting = "another thing"
mylist.Add(tmpstruct)
For Each tmpstruct In mylist
ListBox1.Items.Add(tmpstruct.someting)
Next
Dim binder As New BindingSource
binder.DataSource = mylist
ListBox2.DataSource = binder
ListBox2.DisplayMember = "something"
End Sub
One of the really cool things I see in .NET is the ability to bind a data aware control to just about anything. However, I can't make it work right to save my life.
I don't get any errors, but the control is being populated with the name of the structure I created the BindingList on instead of the contents of the Binding list.
The test code below demonstrates the issue. When the below code runs, listbox1 populates with "one thing" and "another thing" as it should. Listbox2 however populates with "test.Form1+simplestruct" and "test.Form1+simplestruct".
I know the BindingList contains the data because I can access it direclty using "?ctype(binder.Current,simplestruct).someting" from the immidiate window while paused and it returns "one thing".
What the heck am I doing wrong??
Steve Z
Public Structure simplestruct
Dim someting As String
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mylist As New System.ComponentModel.BindingList(Of simplestruct)
Dim tmpstruct As New simplestruct
tmpstruct.someting = "one thing"
mylist.Add(tmpstruct)
tmpstruct.someting = "another thing"
mylist.Add(tmpstruct)
For Each tmpstruct In mylist
ListBox1.Items.Add(tmpstruct.someting)
Next
Dim binder As New BindingSource
binder.DataSource = mylist
ListBox2.DataSource = binder
ListBox2.DisplayMember = "something"
End Sub