Solved

How do you set default selected in a combo box in c#.net

Posted on 2011-02-17
11
521 Views
Last Modified: 2012-05-11
How do you set default selected in a combo box in c#.net
0
Comment
Question by:rockhammer99
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 15

Accepted Solution

by:
Russell_Venable earned 250 total points
ID: 34921428
cmbBox.SelectedIndex = 0; //<-- Set the number of the index location of the option you want as your default here

Open in new window

0
 
LVL 16

Assisted Solution

by:BurnieP
BurnieP earned 250 total points
ID: 34921763
If you don't know the index you can set it by value also.

cb.SelectedValue = "MyValue"l
0
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 34921920
Also take note you can do that this way as well.
cmbBox.SelectedIndex = cmbBox.FindString(@"YourValueHere");

Open in new window


This will give you the index of the Value you want. You can test it by setting a seperate integer and calling it like this.
int index = cmbBox.FindString(@"YourValueHere");
System.Windows.Forms.MessageBox.Show(index);

Open in new window

0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34922275
Hi,

This will show the possible ways additionally.
http://www.dotnetspider.com/forum/161988-Combo-box-default-Selection-C.aspx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:starlite551
ID: 34928088
Try this method :
public void SearchComboBox(ComboBox cbTest,string searchValue,string searchFlag)
{
       switch(searchFlag)
       {
             case "I" :
                cbTest.SelectedIndex = Int32.Parse(searchValue);
                break;
             case "V" :
                cbTest.SelectedValue = searchValue;
                break;
             case "T" :
                cbTest.SelectedItem.ToString() = searchValue;
                break;
             default :
                cbTest.SetSelected(0,true);//Select First Index..     
                break;                  
       }
}

Open in new window

0
 
LVL 12

Expert Comment

by:starlite551
ID: 34928130
How to call above method ?? Answer is this way :
SearchComboBox(comboBox1,"2","I"); //TO SELECT 2nd Index Position.
SearchComboBox(comboBox1,"myValue","V"); //TO SELECT Value "myValue" from list..
SearchComboBox(comboBox1,"xyz","lkj"); //TO SELECT 0 index by default..

Open in new window

0
 
LVL 5

Expert Comment

by:knowlton
ID: 36122545
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 36122546
Hi,

I have provided the possible solution in comment http:#34922275 Pls review the answers for the question asked before taking decision. And accordingly close the issues.
0
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 36122980
I get these all the time even though I give them many different solutions. Seems to be more often too. Ignoring your own type of deal here. It's what we have come to know it as a "Fire & Forget" question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now