Binding listbox items

M

mick

I have two tables and I want to bind 4 items from the 2nd table into a
listbox.
The two tables are called "Games" and "Disks".
Can this be done using the VStudio settings - which I`ve been trying to do
but
know what combination I should be using for the SelectedIndex SelectedItem,
SelectedValue fields. I've set the Datasource to DisksBindingSource which I
assume is correct. The best I've been able to achieve is filling the listbox
with
four "System.Data.DataRowView"s:) As is probably obvious I'm pretty (very)
new to databases and this binding stuff.

mick
 
M

mick

Peter Duniho said:
SelectedIndex allows you to set or get the currently selected item index.
SelectedItem and SelectedValue return the object associated with the
current selection index, and the "value member" of that object,
respectively. You control what member of the object is the "value member"
by setting the ValueMember property of the ListBox.


It's hard to know for sure what you need help with, without a more
complete question (including a concise-but-complete code sample). But, I
think it's possible (perhaps even likely?) that all you need at this point
is to set the DisplayMember property of your ListBox to the name of the
property on your table element that you want to actually display in the
ListBox itself.

For example, if your objects had a property called "Name", you could set
the DisplayMember property of the ListBox to the string "Name", and then
the ListBox would know to use that property when displaying each item in
the ListBox.

I`ll try to make it clearer.
Tables -

Games
GameID (Primary Key)
...
...
...

Disks
DiskID
Disk1
Disk2
Disk3
Disk4
GameID (For. Key)

What I want is for the Listbox to show the contents of Disk1, Disk2, Disk3,
Disk4 for a particular datarow. How do I do the binding so it will show
these four fields. Obviously I can only set the DisplayMember to one of
these fields and not to all.

Any clearer?

mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top