Solved

How to set default value in ComboBox

Posted on 2013-11-04
2
1,443 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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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