Setting the default index of my combo box only on initial open

27,582

Solution 1

If you want to set particular index of combobox as a default value set the index within form load,

private void Form1_Load(object sender, EventArgs e)
{
    //To make combobox non editable
    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

    //Set preferred index to show as default value
    comboBox1.SelectedIndex = 2;
} 

Solution 2

In the design time, you can select using below way:

    <ComboBox x:Name="OfferTypesComboBox" Grid.Row="2"  Grid.Column="1" Margin="2" **SelectedIndex="0"**>
        <ComboBoxItem Content="All" HorizontalAlignment="Left" Width="194"/>
        <ComboBoxItem Content="HSIA" HorizontalAlignment="Left" Width="194"/>
        <ComboBoxItem Content="IPTV" HorizontalAlignment="Left" Width="194"/>
    </ComboBox>
Share:
27,582
theGreenCabbage
Author by

theGreenCabbage

A software developer and supporter of any language that facilitates open source methodologies, extensibility, versatility and collaboration. Currently Using: PHP, MySQL, and bash. Current Projects: OpenCart module development. I am also the only living programmer that's also a part time leafy green veggie. Yeah. I'm that good. I make you green with envy. Bachelor of Science in Computer Engineering Minor in Computer Science Grasshopper 3D developer KT Tools. A Grasshopper 3D tool suite I authored Make Eclipse Look and Work More Like Visual Studio

Updated on July 14, 2022

Comments

  • theGreenCabbage
    theGreenCabbage almost 2 years

    In response to this question: VS2010/C#: How do you set the default value of a ComboBox in the IDE?

    According to that user, in the Delphi IDE, one is able to, in the Properties window, set the DEFAULT INDEX of a comboBox when you open it INITIALLY. However, no where can I find Default Index anywhere. When I mean initially, I mean not programmatically, and at the same time if and only if it's opened initially.

    I've tried setting the index through comboBox.SelectedIndex = 0, but it turns out that I would be setting it every time I run the program, so that happens not only initially, but every time I run the program. Not what I want.

    Does anyone know what I can do in the properties or argument events window on how I can do that..?

    When I open my program initially, this is what it looks like:

    enter image description here

    My Properties tab:

    enter image description here

    EDIT: I could create a global integer counter which increments on each run, and have the default value set as 0 if and only if the integer is 0, meaning it's the first run, but if it's something I can do without doing it programmatically, that would be better.