Solved

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

Posted on 2011-02-17
11
527 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 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