473,569 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get value of 3rd column in combobox attached to a dataset t

I created a table in a dataset that contains multiple columns. I attached a
combo box to that table. Now I'm doing something wrong with trying to
retrieve the value of the third column of the selecteditem.

The datatable row contains the following columns, (ProductCd, Description,
ProductType), the displaymember is Description, and the valuemember is
ProductCd.

I know how to get the values of the displaymember and valuemember, but how
do I get the value of the ProductType for the selecteditem?

Thanks
Vern
Nov 17 '05 #1
2 11267
I may have found the answers to my own question.

If the combobox is attached to a datatable, then the following seems to work:
DataTable table = (DataTable)comb obox1.DataSourc e;
string textfield =
table.Rows[combobox1.Selec tedIndex]["column_nam e].ToString();

If the combobox is attached to a dataview:
DataView view = (DataView)combo box1.DataSource ;
string textfield = view[combobox1.Selec tedIndex]["column_nam e"].ToString();

Let me know if there is a better way.
"Vern" wrote:
I created a table in a dataset that contains multiple columns. I attached a
combo box to that table. Now I'm doing something wrong with trying to
retrieve the value of the third column of the selecteditem.

The datatable row contains the following columns, (ProductCd, Description,
ProductType), the displaymember is Description, and the valuemember is
ProductCd.

I know how to get the values of the displaymember and valuemember, but how
do I get the value of the ProductType for the selecteditem?

Thanks
Vern

Nov 17 '05 #2
I was shown in another newsgroup, a more direct way to get the answer. I had
tried to do this, but wasn't able to get the correct syntax. Anyway, the
combobox stores each row in an object that is retrievable using the
selecteditem property. Here's the code that maps the selecteditem to a
datarowview so it can extract the column data.

sField1.Text =
((DataRowView)s Combobox1.Selec tedItem)["ColumnName "].ToString();
"Vern" wrote:
I may have found the answers to my own question.

If the combobox is attached to a datatable, then the following seems to work:
DataTable table = (DataTable)comb obox1.DataSourc e;
string textfield =
table.Rows[combobox1.Selec tedIndex]["column_nam e].ToString();

If the combobox is attached to a dataview:
DataView view = (DataView)combo box1.DataSource ;
string textfield = view[combobox1.Selec tedIndex]["column_nam e"].ToString();

Let me know if there is a better way.
"Vern" wrote:
I created a table in a dataset that contains multiple columns. I attached a
combo box to that table. Now I'm doing something wrong with trying to
retrieve the value of the third column of the selecteditem.

The datatable row contains the following columns, (ProductCd, Description,
ProductType), the displaymember is Description, and the valuemember is
ProductCd.

I know how to get the values of the displaymember and valuemember, but how
do I get the value of the ProductType for the selecteditem?

Thanks
Vern

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
3249
by: DraguVaso | last post by:
Hi, The Multi column comboBox is a well spoken control, that a lot of people desire, and a lot of people buildtheir own. I tested a lot of them, but none really was what i wanted to have. But does anybody knows where I can find the best Multi column combobox? One that supports a lot of columns, possiblities to get the values in each column...
6
7473
by: Omar | last post by:
When I try to databind my comboBox (specifically field "emplcode") to a filled dataset , the contents of the comboBox displays a bunch of "System.Data.DataRowView". I assume the amount of times "System.Data.DataR..." is displayed inside the combobox is the amount of records in the dataset. On the other hand, if my query is "select emplcode...
12
4698
by: Dica | last post by:
i can't seem to find a way to cast the value in my comboBox to integer. i've tried the following: short iProjectID = Convert.ToInt16(cboProjects.SelectedValue); i keep getting a "Sepcified cast is not allowed" error. how can i do this?
1
1194
by: Lasse Eskildsen | last post by:
Hi, I have added a new column to my dataset, but how do I save this to the database? I can only make "Oledbdataadapter.update(dataset)" write rows to the database. Thanks in advance! --
2
4516
by: jaYPee | last post by:
i have search a lot of newsgroup and some website to find a sample for multi column combobox in datagrid but no luck. there are so many sample i found but it is not located in datagrid. i would be very glad if you can direct me to a website that has this sample thanks in advance.
8
2335
by: Myron Marston | last post by:
For a WebService I am developing, I return a DataSet that contains a table listing Field Names and Field Values. The FieldValue column is given the type object becuase it can potentially contain any of the primative value types (date, int, decimal, string, bool, etc). However, when my client consumes the webservice, it is always a string,...
1
1825
by: Rob | last post by:
I understand how to populate a list box from a data set... it has a DataSource property... but how do you populate a Textbox with the the contents of a column from a DataSet. FYI - The data set will only contain one row of data. Thanks !
3
3666
by: greeknl via AccessMonster.com | last post by:
Is possible to save to a variable in VBA the value a combobox had before it was updated in order to use it because the update value can be retrieved easily Thank you -- Message posted via http://www.accessmonster.com
1
3126
by: vgarzon | last post by:
Hi, I'm having issues setting a multi-column combobox in the right way. What I'm trying to do is that when I click on a table (access 2007 subform), a form should fill with the values of the record I clicked on. No problem until I have to fill correctly a multi-column combo for 2 reasons: - In the table I only have the value of one of...
0
994
by: wasim jack | last post by:
sir,I want to change value of combobox of datagridview on the basis of previous combobox value of the same raw of same datagridview
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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...
0
7924
Oralloy
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. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
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...
0
6284
agi2029
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...
0
5219
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
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 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.