473,602 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When is Winforms Combobox.Select edValue a string?

Hi,
I generally work on web apps, but I am dealing with a Winform right now
and may be missing something really basic.
I have a combobox and I would like to know what value has been selected.
When I try to get the value as a string I sometimes get errors because
Combobox.Select edValue is a DataRowView and when I try to get the value by
first casting as a DataRowView I sometimes get errors because I can't cast a
string to a DataRowView! I have not been able to track down when the value is
what and, while I could check for type, that seems really cumbersome for just
getting a simple value! Anyone know what I am missing?
More details: The combobox starts life without any items. It gets a
datatable as a datasource when the Tab of a Tabcontrol, on which it resides,
is selected. The databinding looks like this:

public static void BindeNumToList( System.Windows. Forms.ListContr ol
theControl, Type EnumType)
{
theControl.Data Source = eNumByDescripti onAsDataTable(E numType);
theControl.Disp layMember = "Displays";
theControl.Valu eMember = "Values";
}

where eNumByDescripti onAsDataTable is a method which generates a simple
datatable with a "Values" column and a "Displays" column from an eNum type.

The code which tries to find the value of the combobox looks like this:
DataRowView SelectedRow = (DataRowView)Ki tUsedBox.Select edValue;
KitUsed TheKit = (KitUsed)int.Pa rse(SelectedRow[0].ToString());
// KitUsed TheKit =
(KitUsed)int.Pa rse(KitUsedBox. SelectedValue.T oString());

The uncommented part sometimesworks and sometimes throws errors. When I
switch and just have the part the is currently commented, I get the same
general behavior. Sometimes works, sometimes throws errors.

Thanks for your help!
Ethan
Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
ethan.strauss atsign promega.com
Jun 27 '08 #1
1 7240
From memory, you'll get this sort of behaviour when you have no
datasource (i.e. it either hasn'e been set or is set to null) - so I
would check that your BindeNumToList is working properly,
On May 16, 5:08 am, Ethan Strauss
<EthanStra...@d iscussions.micr osoft.comwrote:
Hi,
I generally work on web apps, but I am dealing with a Winform right now
and may be missing something really basic.
I have a combobox and I would like to know what value has been selected.
When I try to get the value as a string I sometimes get errors because
Combobox.Select edValue is a DataRowView and when I try to get the value by
first casting as a DataRowView I sometimes get errors because I can't cast a
string to a DataRowView! I have not been able to track down when the value is
what and, while I could check for type, that seems really cumbersome for just
getting a simple value! Anyone know what I am missing?
More details: The combobox starts life without any items. It gets a
datatable as a datasource when the Tab of a Tabcontrol, on which it resides,
is selected. The databinding looks like this:

public static void BindeNumToList( System.Windows. Forms.ListContr ol
theControl, Type EnumType)
{
theControl.Data Source = eNumByDescripti onAsDataTable(E numType);
theControl.Disp layMember = "Displays";
theControl.Valu eMember = "Values";
}

where eNumByDescripti onAsDataTable is a method which generates a simple
datatable with a "Values" column and a "Displays" column from an eNum type.

The code which tries to find the value of the combobox looks like this:
DataRowView SelectedRow = (DataRowView)Ki tUsedBox.Select edValue;
KitUsed TheKit = (KitUsed)int.Pa rse(SelectedRow[0].ToString());
// KitUsed TheKit =
(KitUsed)int.Pa rse(KitUsedBox. SelectedValue.T oString());

The uncommented part sometimesworks and sometimes throws errors. When I
switch and just have the part the is currently commented, I get the same
general behavior. Sometimes works, sometimes throws errors.

Thanks for your help!
Ethan

Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
ethan.strauss atsign promega.com
Jun 27 '08 #2

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

Similar topics

3
4252
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
1
6724
by: KlaasIMN | last post by:
Using a combobox I want to retrieve the index of a given value in a combobox. object sel = combo.SelectedValue; string selectedvalue = sel.ToString(); ComboBox.ObjectCollection items = combo.Items; int i = items.IndexOf(sel);
1
9461
by: nickyw | last post by:
Hi, Can anyone help, I want to get a reference to a combobox item based on the item's value rather than the text (basically what I am asking is, is there a function like 'FindStringExact' for values) , does anyone know how to do this? Thanks, Nicky
12
4703
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?
30
4557
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 corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
7
4555
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table (called "Data") with two columns "Id" and "Description". Id contains a code and description contains the description that is displayed in the combobox.
2
10308
by: Mark Rae | last post by:
Hi, Just looking for some v2 guidance here... In WebForms, the DropDownList control has an Items collection which contains ListItem objects which, in turn, very conveniently contain a text property and a value property. In WinForms, the ComboBox control also has an Items collection which can contain (as I understand it) pretty much any object which can display
3
61132
by: Nofi | last post by:
Hello, I'm trying to fill my combobox per code, not with a DataSet because I want to have an empty row in it and this wasn't possible when working with a DataSet. The fill works fine, but when I set the value and display member I get false values. string sConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Dokumente und Einstellungen\KosiorekA\Eigene Dateien\VS2005 Projects\CromaRENT\CromaRENT-DB\CromaRENT-DB.mdb";
2
2441
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the databases in that server. Then after the user selects a database, I have another button that he/she click and I want to retrieve file groups from a specific table. At this point when he/she clicks on that button I get an error:
0
7993
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8268
tracyyun
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...
0
6730
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
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
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.