Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:11:30+00:00 2026-05-16T01:11:30+00:00

<ComboBox Grid.Row=1 Grid.Column=0 Width=Auto Name=cmbBudgetYear> <ComboBoxItem Content=2009 /> <ComboBoxItem Content=2010 /> <ComboBoxItem Content=2011 />

  • 0
<ComboBox Grid.Row="1" Grid.Column="0" Width="Auto" Name="cmbBudgetYear">
   <ComboBoxItem Content="2009" />
   <ComboBoxItem Content="2010" />
   <ComboBoxItem Content="2011" />
   <ComboBoxItem Content="2012" />
</ComboBox>

How do I set the selected item to the current year in the code behind?

Something like…

cmbBudgetYear.SelectedItem = cmbBudgetYear.Items(
                                         get the item with the Now.Year.ToString)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:11:31+00:00Added an answer on May 16, 2026 at 1:11 am

    There exist many ways to do this but for your example, I would change the ComboBox-Tag as follows:

    <ComboBox Grid.Row="1" Grid.Column="0" 
              Name="cmbBudgetYear" SelectedValuePath="Content">
    

    I added the attribute-defition SelectedValuePath="Content". After that you can set the value with a corresponding string, e.g.:

    cmbBudgetYear.SelectedValue = "2009";
    

    Take care that the value must be a string. For your example, use

    cmbBudgetYear.SelectedValue = DateTime.Now.Year.ToString();
    

    An additional idea

    If you use the code-behind anyway, would it be a possibility to fill the combobox with integers. Someting like:

    for(int y=DateTime.Now.Year;y>DateTime.Now.Year-10;y--){
     cmbBudgetYear.Items.Add(y);
    }
    

    ..then you can select the values extremly simple like

    cmbBudgetYear.SelectedValue = 2009;
    

    … and you would have also other advantages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is peace of the XAML code from my page: <ComboBox Grid.Row=2 Grid.Column=1 Name=Player2
I have WPF combobox bound to a ObservableCollection ItemCategoryList <ComboBox Grid.Column=1 Grid.Row=2 Height=Auto HorizontalAlignment=Stretch
Here's my code: <ComboBox Grid.Column=1 Grid.Row=9 ItemsSource={Binding Path=PriorityEntries} SelectedItem={Binding Path=Priority,Mode=TwoWay}/> The comboBox is bound
<ComboBox Grid.Column=1 Grid.Row=1 ItemsSource={Binding Locations} SelectedItem={Binding SelectedLocation} Margin=5 MinWidth=125> <ComboBox.ItemContainerStyle> <Style TargetType={x:Type ComboBoxItem}> <Style.Triggers>
I've got the following.. <ComboBox Grid.Row=2 Grid.Column=2 Grid.RowSpan=2 ItemsSource={Binding ShipperAddresses} Text={Binding ShipperAddress} Margin=85,2,0,2> <ComboBox.ItemTemplate>
I got a combobox in the grid's column: <ListView> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate>
I have a ComboBox whose XAML looks as follows: <StackPanel Grid.Row = 0 Style={DynamicResource
Given that every grid, combobox, checkboxlist and in general multi row control supports binding
i have the following combobox <ComboBox Grid.Column=1 HorizontalAlignment=Stretch Text={Binding GroupInvoicing.AdminInvoiceBreakdownMembership} SelectedValuePath=Tag SelectedValue={Binding Path=GroupInvoicing.AdminInvoiceBreakdownMembership}> <ComboBoxItem
I have some data presented in WPF Grid as follows: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width=Auto

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.