Groups | Blog | Home
all groups > dotnet windows forms databinding > november 2006 >

dotnet windows forms databinding : Binding Listbox to child table



rwwagner NO[at]SPAM geodecisions.com
11/14/2006 2:04:52 PM
Is it possible to bind a listbox to a child table so that it will only
display the child records based on the current parent record?
rwwagner NO[at]SPAM geodecisions.com
11/15/2006 5:19:46 AM

[quoted text, click to view]


Thanks for you help. I'm using 1.1 and I already have the tables
loaded with the datarelation. I'm using a strongly-typed dataset. I
would like to do this in code.

Bob
rwwagner NO[at]SPAM geodecisions.com
11/15/2006 5:20:05 AM

[quoted text, click to view]


Thanks for you help. I'm using 1.1 and I already have the tables
loaded with the datarelation. I'm using a strongly-typed dataset. I
would like to do this in code.

Bob
rwwagner NO[at]SPAM geodecisions.com
11/15/2006 10:30:52 AM
Bart,

I'm still having issues. Here is what I have. This is in vb by the
way...


childListBox.DataSource = yourDataSet
childListBox.DisplayMember =
"SomeParentTable.YourParentToChildRelation.SomeTextField"
childlistBox.ValueMember =
"SomeParentTable.YourParentToChildRelation.SomeTextField"

I also have currency managers defined:

cmParent = Me.BindingContext(myDataSet, "ParentTable")
cmChild = Me.BindingContext(muDataSet,
""ParentTable.YourParentToChildRelation")


What I get displayed in the list box is the text
"System.Data.DataViewManager"

any ideas?

Thanks
Bart Mermuys
11/15/2006 12:56:57 PM
Hi,

[quoted text, click to view]

Yes it is. But how you would do it depends on which framework you are using
1.1 or 2.0, whether you want to do this using the designer or from code. Do
you already have the parent and child DataTable loaded, is there already a
DataRelations between them, etc.

HTH,
Greetings



Bart Mermuys
11/15/2006 2:51:22 PM
Hi,

[quoted text, click to view]

If you have all that, then it's just a matter of binding correctly, eg. :

// parent
SomeTextBox.DataBindings.Add("Text", yourDataSet,
"SomeParentTable.SomeTextField");

// child listbox
childListBox.DataSource = yourDataSet;
childListBox.DisplayMember =
"SomeParentTable.YourParentToChildRelation.SomeTextField";

HTH,
Greetings

[quoted text, click to view]

Bart Mermuys
11/15/2006 6:55:58 PM
Hi,

[quoted text, click to view]

Not many. This is usually an indication that ComboBox.DisplayMember hasn't
been set, but i assume you did set it, so i don't know what's wrong. I did
try a simple test app using the same code and it did work. Maybe you can
post more code or the entire Form code if it isn't that big....

HTH,
Greetings


[quoted text, click to view]

rwwagner NO[at]SPAM geodecisions.com
11/16/2006 7:27:55 AM
Bart,


Below is my code. I set up a simple form to test this and it still
doesn't work properly. Maybe you can see something that I am doing
wrong. The people table will have multiple people returned. When I
change the cmPeople.position property the form correctly displays the
first and last name of the person.


' strongly typed dataset with people table (parent), id_numbers
(child) table and relation (peopleid_numbers) defined between the two
Dim peopleDS As New DataLayer.PeopleDS
' class that loads data into dataset - datatables
Dim PeopleDA As DataLayer.PeopleDA

Dim cmPeople As CurrencyManager
Dim cmIDNumbers As CurrencyManager


' load data into dataset
PeopleDA = New DataLayer.PeopleDA(people)
PeopleDA.GetPeopleByCaseKey(10)



cmPeople = Me.BindingContext(peopleDS, "PEOPLE")
cmPeople.Position = 0

cmIDNumbers = Me.BindingContext(peopleDS,
"PEOPLE.PEOPLEID_NUMBERS")
cmIDNumbers.Position = 0


Me.TextBox1.DataBindings.Add("Text", peopleDS, "people.lname")
Me.TextBox2.DataBindings.Add("Text", peopleDS, "people.fname")

Me.ListBox1.ValueMember = "PEOPLE.PEOPLEID_NUMBERS.idnumkey"
Me.ListBox1.DisplayMember = "PEOPLE.PEOPLEID_NUMBERS.idnumber"
Me.ListBox1.DataSource = peopleDS


I appreciate all of your help....

Bob
rwwagner NO[at]SPAM geodecisions.com
11/16/2006 9:23:20 AM
Hi Bart,

You example worked for me once I found a stupid typo that I had in my
code. Thanks for your help....

Bob
rwwagner NO[at]SPAM geodecisions.com
11/16/2006 9:23:31 AM
Hi Bart,

Your example worked for me once I found a stupid typo that I had in my
code. Thanks for your help....

Bob
Bart Mermuys
11/16/2006 7:08:26 PM
Hi,

[quoted text, click to view]

Glad you found the problem.

[quoted text, click to view]

You're welcome.
Greetings

[quoted text, click to view]

AddThis Social Bookmark Button