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 4 2488
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***@discussi ons.microsoft.c om> 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]
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***@discussi ons.microsoft.c om> 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]
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***@discussi ons.microsoft.c om> 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***@discussi ons.microsoft.c om> 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]
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.DataRowVie w(cmboxPersonne lType.SelectedI tem)).Row.ItemA rray[0]);
1) ComboBox.Select edItem = Returns an object (Data row with your data)
2) Take the object from ComboBox.Select edItem -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 PersonnelTypeRe cordID
{
get
{
return
(int)(((System. Data.DataRowVie w)(cmboxPersonn elType.Selected Item)).Row.Item Array[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***@discussi ons.microsoft.c omwrote:
>
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]
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
CustomerID CustomerName City
|
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 lookup descriptions. How do I bind
them up in this case?
Thanks
Steve
|
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 lookups into
another table called "defects table". If I input from the CVA Defects
Table everything works fine all the time. However when I input data
from the form I have problems.
The Oil & Gas line lookups work very well all the time in the form....
|
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 by
Utility", sqlConn)
|
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!
Private Sub Get_Data()
Try
Dim sqlcmd = New SqlCommand("Select * from Utility order by
| |
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 field in the
dataset I wish to utilize. When I run the form the combo box has no
information. What am I doing wrong?
Thanks!!
Travis
|
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 allow user to filter the first time,
when they tried the second time, the speficied cast error message will
prompt one....
I create a mydataset1 first, and the mydataset1 data source was getting from
DataGrid.DataSource.
|
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 combos based on lookups of very small tables, Audit
Descriptions and Programs.
Combo 1: Audit Descriptions has Comprehensive, Fire Safety, Medical,
MSC, Snapshot.
Combo 2: Programs has A, B, C, D, E, F, G, H (for example).
|
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:
cb.DataSource=myDataSet.Tables;
cb.DisplayMember = "Description";
cb.ValueMember = "Description";
Problem is my Combobox remains with 0 items instead of the 80 rows in the datasource!!!
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |