473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use the selectedITem or SelectedValue when selecting an item from a combobox?

2 New Member
I have the following problem

How do you select an item from a combobox when this combobox receives data from a SQL database.
Expand|Select|Wrap|Line Numbers
  1.  
  2. private void cmbMDCTestRequirements_SelectedValueChanged(object sender, EventArgs e)
  3.  
  4. Object selectedRequirement = cmbMDCTestRequirements.selectedItem;
  5.  
  6. Now this Object should be changed into an integer.
  7.  
  8. How should this be done ?
  9.  
  10.  
The cmbMDCTestRequirements firs tis filled with data uysing the following code:

Expand|Select|Wrap|Line Numbers
  1.         private void FillDataInApplicationRequirementComboBox()
  2.         {
  3.             cmbMDCTestRequirements.DataSource = null;
  4.             ApplicationSettings appSettings = new ApplicationSettings();
  5.             dataset = appSettings.getApplicationRequirements();
  6.             dsView = dataset.DefaultViewManager;
  7.             cmbMDCTestRequirements.ValueMember = "ApplicationRequirements.Id";
  8.             cmbMDCTestRequirements.DisplayMember = "ApplicationRequirements.RequirementDescription";
  9.             cmbMDCTestRequirements.DataSource = dsView;
  10.  
  11.             totalCustomerRequirements = cmbMDCTestRequirements.Items.Count;
  12.             txtTotalCustomerRequirements.Text = totalCustomerRequirements.ToString();
  13.         }
  14.  
  15.  
  16.  
Jan 4 '11 #1
2 1869
GaryTexmo
1,501 Recognized Expert Top Contributor
Can you use SelectedIndex, perhaps?
Jan 6 '11 #2
Frans vd Heuvel
2 New Member
Hi Gary, thanks for you answer, but no i don't like to use the SelectedIndex, because it gives the position in the combobox and not in the table of the database. but in the meantime i already have found the answer.

The answer is using the

Expand|Select|Wrap|Line Numbers
  1. DataRowView selectedRequirementItem = cmbMDCTestRequirements.SelectedItem as DataRowView;
  2. if (selectedRequirementItem != null)
  3.   {
  4.      SelectedValue = selectedRequirementItem.Row.ItemArray[0].ToString();
  5.   }
  6.  
Now you really select the Id of a record of the database.

Thanks for your quick answer
Jan 6 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1904
by: Amin Gunawan via .NET 247 | last post by:
I would like to put a combo box in a column of a datagrid. I've seen the samples in the MSDN library of other sources, butall samples didn't catch the 'DOWN/UP' keystroke. It means thatwhen I select...
2
1933
by: Martin Maat | last post by:
I am almost longing for MFC (no, not really, but a couple of things seem to be less powerfull in Windows.Forms). One is updating menu item status. Having commands separated from the UI thingies...
3
2047
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
2
1304
by: Aaron Ackerman | last post by:
I have been having just on going problems with my MS Datagrids. I have NO idea what I am doing wrong. What is esentially happening is that say I have three records in my Dataset. I click on the...
2
1766
by: Derek Vincent | last post by:
Using Visual Studio.net 2003 to create an aspx web form I am having a problem selecting an item from DropDownListBox with id= ListBoxStudies. I can see the items from the bound database table but...
5
1395
by: stephen | last post by:
Hi, I have a place holder and I have a checkboxlist in it? why do i get a "System.NullReferenceException: Object reference not set to an instance of an object." error why I try to get the...
7
1289
by: daokfella | last post by:
I have a business object that exposes a collection of other objects via a List<of Type>. How can I intercept when an item is either added or removed from this list. Is it possible? private...
1
7227
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
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....
0
1075
by: Jeff | last post by:
Hi asp.net 2.0 My webpage has a DataList containing a TemplateField (ImageButton). When the ImageButton is clicked it becomes the selected ImageButton. This works okay as it is. But this...
0
1259
by: BigRedEO | last post by:
I am needing to SELECT all fields/records from a large table (96 columns, over 100 million records) into an outfile. I need to change any "NULL" to a blank. I can use "SELECT...
0
7093
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
7287
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,...
0
7349
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...
0
5594
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,...
0
4688
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...
0
3177
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...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
1
746
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.