Solved

How to set default value in ComboBox

Posted on 2013-11-04
2
1,412 Views
Last Modified: 2013-11-04
Hello Experts!

I have attached the code snippets below. Basically I am building a ComboBox in code. The box itself is on the window but I am generating all of the contents in code.

ComboBox WPF Control
<ComboBox x:Name="cboReminderTime" Text="Please select an item" HorizontalAlignment="Left" Margin="150,588,0,0" VerticalAlignment="Top" Width="120"/>

Open in new window


ComboBox Population Control (Snippet)
if (intHoursTillEvent >= 24)
            {
                cboReminderTime.Items.Clear();
                cboReminderTime.Items.Add("15 Minutes");
                cboReminderTime.Items.Add("1 Hour");
                cboReminderTime.Items.Add("3 Hours");
                cboReminderTime.Items.Add("6 Hours");
                cboReminderTime.Items.Add("12 Hours");
                cboReminderTime.Items.Add("24 Hours");
                cboReminderTime.Items.Add("Start Now");

            } // closes >= 24 hours

Open in new window


There are many other hour values it will evaluate against. In all of them, the "15 Minutes" option is the first one in the list and the one I want to set as the default.

I am very new to C# and brand new to WPF. I have VB.Net (WinForm) experience so I am picking this up with decent pace, but I am not getting this one. Google is not being the most helpful this morning either (prob my fault).

Thanks for the help guys and gals!
0
Comment
Question by:LouisM1979
2 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 39621525
you can set the default value with the index.

cboReminderTime.SelectedIndex = 0;

Open in new window

0
 

Author Closing Comment

by:LouisM1979
ID: 39621554
I thought I tried that. >.<.

Thanks for the support!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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