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

Bind my dataset to combo lookups?

P: n/a

C#

I have some combo boxes, full of lookup descriptions. When I retrieve a
dataset for my record, the values that need binding to the combos are the
actual record IDs that relate to these lookup descriptions. How do I bind
them up in this case?

Thanks

Steve
Nov 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Steve,

I'm not exactly sure of what you are asking for, but I suspect you may be looking for the ValueMember/DisplayMember properties of the ComboBox. Typically the DisplayMember is the column the describes the entry and ValueMember the column that contains the id.
On Mon, 19 Sep 2005 14:39:26 +0200, Steve <St***@discussions.microsoft.com> wrote:

C#

I have some combo boxes, full of lookup descriptions. When I retrieve a
dataset for my record, the values that need binding to the combos are the
actual record IDs that relate to these lookup descriptions. How do I bind
them up in this case?

Thanks

Steve


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 22 '05 #2

P: n/a

When the user enters the screen to modify a record, I populate a dataset row
with all the values from the DB, then I am trying to bind that set into the
screen, so I can capture all the changes, then return the dataset to the
server to commit the changes. With text fields I can bind them no problems,
and the value is displayed nice and easy. But with the combos, the value
stored is the ID field of the combo box. How do I tie these together so the
combo is changed to show the correct descriptor and how do I then get the
combo change to change the value in the dataset?

Thanks

Steve

"Morten Wennevik" wrote:
Hi Steve,

I'm not exactly sure of what you are asking for, but I suspect you may be looking for the ValueMember/DisplayMember properties of the ComboBox. Typically the DisplayMember is the column the describes the entry and ValueMember the column that contains the id.
On Mon, 19 Sep 2005 14:39:26 +0200, Steve <St***@discussions.microsoft.com> wrote:

C#

I have some combo boxes, full of lookup descriptions. When I retrieve a
dataset for my record, the values that need binding to the combos are the
actual record IDs that relate to these lookup descriptions. How do I bind
them up in this case?

Thanks

Steve


--
Happy coding!
Morten Wennevik [C# MVP]

Nov 22 '05 #3

P: n/a
Your scenario is still not entirely clear to me, but that may be my fault :)
Correct me if I'm wrong, but I'm guessing you have an ID field in your row representing data from another table and want the id number translated to this data, with the ComboBox selection tied to that table (Lookup Table).

Maybe this page can be of some use (beware of line breaks):

http://msdn.microsoft.com/library/de...boxcontrol.asp
On Mon, 19 Sep 2005 15:51:00 +0200, Steve <St***@discussions.microsoft.com> wrote:

When the user enters the screen to modify a record, I populate a dataset row
with all the values from the DB, then I am trying to bind that set into the
screen, so I can capture all the changes, then return the dataset to the
server to commit the changes. With text fields I can bind them no problems,
and the value is displayed nice and easy. But with the combos, the value
stored is the ID field of the combo box. How do I tie these together so the
combo is changed to show the correct descriptor and how do I then get the
combo change to change the value in the dataset?

Thanks

Steve

"Morten Wennevik" wrote:
Hi Steve,

I'm not exactly sure of what you are asking for, but I suspect you may be looking for the ValueMember/DisplayMember properties of the ComboBox. Typically the DisplayMember is the column the describes the entry and ValueMember the column that contains the id.
On Mon, 19 Sep 2005 14:39:26 +0200, Steve <St***@discussions.microsoft.com> wrote:
>
> C#
>
> I have some combo boxes, full of lookup descriptions. When I retrieve a
> dataset for my record, the values that need binding to the combos are the
> actual record IDs that relate to these lookup descriptions. How do I bind
> them up in this case?
>
> Thanks
>
> Steve
>


--
Happy coding!
Morten Wennevik [C# MVP]


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 22 '05 #4

P: n/a
Hello Steve,

I had the same issue a few days ago. It took me awhile to realize that I was
grabbing the combo box index, not record Id!!!

Anyways, my combo boxes are used in a User Control so you will need to do
something slightly different for a generic combo box.

Basically, I access the underlying List that contains the record information
from the DataSource.

I did this to capture the Record_Id from the Selected List Item:

return
(int)(((System.Data.DataRowView(cmboxPersonnelType .SelectedItem)).Row.ItemArray[0]);

1) ComboBox.SelectedItem = Returns an object (Data row with your data)

2) Take the object from ComboBox.SelectedItem -Or- ComboBox.Item (?) and
cast it to a DataRowView. DataRow should work too.

3) Use the ItemArray property to find the field that you need. The Record_Id
should be an integer.

And that's how you can get your record id without doing too much work. I use
a property to retrieve it.

public int PersonnelTypeRecordID
{
get
{
return
(int)(((System.Data.DataRowView)(cmboxPersonnelTyp e.SelectedItem)).Row.ItemArray[0]);
}
}
"Steve" wrote:
>
When the user enters the screen to modify a record, I populate a dataset row
with all the values from the DB, then I am trying to bind that set into the
screen, so I can capture all the changes, then return the dataset to the
server to commit the changes. With text fields I can bind them no problems,
and the value is displayed nice and easy. But with the combos, the value
stored is the ID field of the combo box. How do I tie these together so the
combo is changed to show the correct descriptor and how do I then get the
combo change to change the value in the dataset?

Thanks

Steve

"Morten Wennevik" wrote:
Hi Steve,

I'm not exactly sure of what you are asking for, but I suspect you may be looking for the ValueMember/DisplayMember properties of the ComboBox. Typically the DisplayMember is the column the describes the entry and ValueMember the column that contains the id.
On Mon, 19 Sep 2005 14:39:26 +0200, Steve <St***@discussions.microsoft.comwrote:
>
C#
>
I have some combo boxes, full of lookup descriptions. When I retrieve a
dataset for my record, the values that need binding to the combos are the
actual record IDs that relate to these lookup descriptions. How do I bind
them up in this case?
>
Thanks
>
Steve
>


--
Happy coding!
Morten Wennevik [C# MVP]
Aug 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.