Solved

How to set default value in ComboBox

Posted on 2013-11-04
2
1,536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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