Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi in asp.net the following code is works fine for dropdown list "ddScreanNameClass"


ddScreanNameClass.SelectedIndex = ddScreanNameClass.Items.IndexOf(ddScreanNameClass.Items.FindByValue("3"));

I need equivalent code in windows form application for comboboxes
Posted
Comments
Vedat Ozan Oner 3-Mar-14 2:04am    
what have you done? Where did you get stuck?
Member 10296413 3-Mar-14 4:27am    
hi i'm saving the value flied Successfully
now I'm doing the Edit code for the Same
I want the combobox should selected to the previously selected item when i click edit
for the same case in Asp dotnet i'm using the code ddScreanNameClass.SelectedIndex = ddScreanNameClass.Items.IndexOf(ddScreanNameClass.Items.FindByValue("3"));
here "3" is the value fled of the item i need to Select pragmatically
i need to do the Same in windows form application for comboboxes please helpme
BillWoodruff 3-Mar-14 5:00am    
Are you populating the WinForms ComboBox using binding to a Data source, so there is a DataMember, and ValueMember property; or, are you manually adding the Items ?
Member 10296413 3-Mar-14 6:05am    
combobox binding code

cProduct obj = new cProduct();
obj.ppro_CompanyId = csession.CompanyId;
obj.ppro_IsActive = "true";
cmbProduct.DisplayMember = "ppro_ProductName";
cmbProduct.ValueMember ="ppro_ProductId";
cmbProduct.DataSource = obj.GetProduct();//returns Array list

1 solution

It probably would have been better to ask "Could someone please show me how to do this in Windows Forms?" rather than what you asked; otherwise (in English at least) you can come across as demanding and rude.

Just saying... :-)

Anyway, this should work:
C#
ddScreanNameClass.SelectedItem = "3";
 
Share this answer
 
Comments
Member 10296413 3-Mar-14 6:06am    
Sorry
Mitchell J. 3-Mar-14 6:11am    
No worries, it's ok if it's a genuine language mistake.
Anyway, did my solution work?
Member 10296413 3-Mar-14 6:21am    
I think you are not observed the right hand side on the assignment operator
the digit "3" is the value field of one item in the combo box Need to select that item proramaticaly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900