By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,333 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,333 IT Pros & Developers. It's quick & easy.

ComboxBox Selection

P: n/a
If I have a table with say Id (key) and Desc, and a ComboBox

box.DataSource = table;
box.ValueMember = table.IDColumn.ColumnName;
box.DisplayMember = table.DescColumn.ColumnName;

and the box has Sorted = true (ie sort on Desc) then when an item is selected,
how do I tie the selected item back to the table ? That is, is there anything in
the selected item that contains the table row or number ?
Mar 27 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Tue, 28 Mar 2006 08:00:25 +1000, Ian Semmel
<is***********@NOKUNKrocketcomp.com.au> wrote:
If I have a table with say Id (key) and Desc, and a ComboBox

box.DataSource = table;
box.ValueMember = table.IDColumn.ColumnName;
box.DisplayMember = table.DescColumn.ColumnName;

and the box has Sorted = true (ie sort on Desc) then when an item is selected,
how do I tie the selected item back to the table ? That is, is there anything in
the selected item that contains the table row or number ?

Isn't the IDColumn the row ID of your table? If it's not use the row ID of the
table instead.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Mar 28 '06 #2

P: n/a
I worked it out,

In box_OnSelectedIndexChanged, :-

DataRowView dv = (DataRowView) box.SelectedItem;

currentID = (int) dv.Row.ItemArray [ table.IDColumn.Ordinal ];

Otis Mukinfus wrote:
On Tue, 28 Mar 2006 08:00:25 +1000, Ian Semmel
<is***********@NOKUNKrocketcomp.com.au> wrote:

If I have a table with say Id (key) and Desc, and a ComboBox

box.DataSource = table;
box.ValueMember = table.IDColumn.ColumnName;
box.DisplayMember = table.DescColumn.ColumnName;

and the box has Sorted = true (ie sort on Desc) then when an item is selected,
how do I tie the selected item back to the table ? That is, is there anything in
the selected item that contains the table row or number ?


Isn't the IDColumn the row ID of your table? If it's not use the row ID of the
table instead.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com

Mar 28 '06 #3

P: n/a
On Tue, 28 Mar 2006 16:14:13 +1000, Ian Semmel
<is***********@NOKUNKrocketcomp.com.au> wrote:
I worked it out,

In box_OnSelectedIndexChanged, :-

DataRowView dv = (DataRowView) box.SelectedItem;

currentID = (int) dv.Row.ItemArray [ table.IDColumn.Ordinal ];

Otis Mukinfus wrote:
On Tue, 28 Mar 2006 08:00:25 +1000, Ian Semmel
<is***********@NOKUNKrocketcomp.com.au> wrote:

If I have a table with say Id (key) and Desc, and a ComboBox

box.DataSource = table;
box.ValueMember = table.IDColumn.ColumnName;
box.DisplayMember = table.DescColumn.ColumnName;

and the box has Sorted = true (ie sort on Desc) then when an item is selected,
how do I tie the selected item back to the table ? That is, is there anything in
the selected item that contains the table row or number ?


Isn't the IDColumn the row ID of your table? If it's not use the row ID of the
table instead.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com

Good job, Ian!
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Mar 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.