Solved

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

Posted on 2011-02-17
11
520 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi,

This will show the possible ways additionally.
http://www.dotnetspider.com/forum/161988-Combo-box-default-Selection-C.aspx
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:starlite551
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What are the big features of MVC5? 4 50
Dialogbox API leak? 18 59
Pass through dll 2 33
getting id from database 5 24
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

12 Experts available now in Live!

Get 1:1 Help Now