473,322 Members | 1,806 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,322 software developers and data experts.

How do I compare DataSourced ComboBox to a value in DataRow?

I seem to be having trouble trying to select the right value in a ComboBox
DataSourced by a DataTable with a value for a DataRow...

For example... In a Windows Form, I have a ComboBox:

ComboBox box = new ComboBox(whatever);
box.DataSource = myDataTable;
box.DataMember = "the_column";

// now select value already in a passed DataRow
DataRow row (the row that's passed in frmo somewhere)
box.SelectedItem = row["the_column"];

Doesn't work...

I tried many variations with TypeCasting and can't get it to work- what's
the secret here?
Nov 16 '05 #1
1 1968
Hi
You need to set both DisplayMemeber ( the column form within the datatable
that would be displayed on your form ) . and the ValueMember ( which is the
real column of the datatable that the combobox is bounded to . A classical
example would be the ID for valueMember while what is displayed is the Name
. then you use the valuemember when you want to set the selectedItem.
this.comboBox1.DisplayMember
this.comboBox1.ValueMember
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

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

Similar topics

3
by: Shravan | last post by:
Hi, How can I bind DataRow array to ComboBox. I tried setting DataSource -> DataRow Array DisplayMember -> ColumnName But it was showing "System.Data.DataRow" for every item in the...
4
by: Beeeeeeeeeeeeves | last post by:
I have an ownerdrawn combo box which I am drawing with an image and some text, this is all working beautifully apart from the difference in the Brush I have to draw the background and the text with...
1
by: MrNobody | last post by:
I created a ComboBox and used one of my DataTables as the DataSource. I set the DisplayMember to the column of the text I want shown to the user while I set the ValueMember to the ID column. I...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: MrNobody | last post by:
If I DataSource a ComboBox to a DataTable, and specify a column for ValueMember and DisplayMember, everything comes out fine until I sort. When I sort, it seems to sort the DisplayMembers...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
2
by: AMDRIT | last post by:
Hello Everyone, I would like to format the Display Members of a combobox's datasource. Is there a way to apply a format without subclassing the original datasource? For example, given a list of...
4
by: c_shah | last post by:
I am a beginner and learning VB.net There are two wasy to bind a combobox or a listbox First approach is to assign a datasource and displaymember Second approach is to iterate through datarow...
8
by: kimtherkelsen | last post by:
Hi, I do this: this.comboBox.DataSource = myDataSet.Tables.Select("location_key = " + selectedLocationKey); this.comboBox.DisplayMember = "text"; this.comboBox.ValueMember =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.