Solved

How to set default value in ComboBox

Posted on 2013-11-04
2
1,364 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
Comment Utility
you can set the default value with the index.

cboReminderTime.SelectedIndex = 0;

Open in new window

0
 

Author Closing Comment

by:LouisM1979
Comment Utility
I thought I tried that. >.<.

Thanks for the support!!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

7 Experts available now in Live!

Get 1:1 Help Now