473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Bind my dataset to combo lookups?


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
4 2450
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: kakss | last post by:
Hi I have a Winforms Datagrid and created myDataView and bind to datagrid. It works great. DataGrid1.SetDataBinding(myDataView, "") Above code line shows me below data in datagrid. ...
3
by: Steve | last post by:
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...
4
by: Don Sealer | last post by:
I have a form that is based on a table called CVA Defects Table. Three of the fields in the table and form are Oil line defects, Gas line defects, and Sub assembly defects. These fields use...
2
by: Ken Powers | last post by:
Hello everyone, I'm getting a strange error when I try to bind a combo box to a Dataset. Here's my code! Private Sub Get_Data() Try Dim sqlcmd = New SqlCommand("Select * from Utility order...
0
by: Ken Powers | last post by:
Hello everyone, Sorry about the repost, my second VB.NET App is done with the exception of this error. I'm getting a strange error when I try to bind a combo box to a Dataset. Here's my code! ...
2
by: Travis | last post by:
I am new to VB.NET and I am trying to use a complex bind for a combo box. I have successfully created a data set, I have set my DataSource value to the dataset and the DisplayMember value to the...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
4
by: tlyczko | last post by:
I read about limiting combo boxes' list data, for example, limiting the list of values in the second combo based on values in the first combo, and I found the Dev Ashish site link. I have two...
1
by: Guy007 | last post by:
I have a dataset with one table, which has a column "Description" in it. the dataset is populated with data. i want to bind the dataset to the combo. i'm doing it as follows: ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.