Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. default value in combobox

default value in combobox

Scheduled Pinned Locked Moved C#
questioncsharp
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarang_k
    wrote on last edited by
    #1

    Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.

    J S R B A 5 Replies Last reply
    0
    • S sarang_k

      Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.

      J Offline
      J Offline
      JF2015
      wrote on last edited by
      #2

      In the designer, you can set comboBox1.Text = "First Item"; or you simply display the first item in your collection in the e.g. form load event.

      1 Reply Last reply
      0
      • S sarang_k

        Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.

        S Offline
        S Offline
        Steven Pinto2000
        wrote on last edited by
        #3

        Use combobox SelectedIndex to select the default value in the combobox:cool:

        1 Reply Last reply
        0
        • S sarang_k

          Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.

          R Offline
          R Offline
          Rick van Woudenberg
          wrote on last edited by
          #4

          When you're application loads, or when the combobox is filled, use this :

          comboBox.SelectedIndex = 0; // ( or 1,2,3 .. depending on the item you'd like to show first )

          1 Reply Last reply
          0
          • S sarang_k

            Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #5

            The two answers above me are correct in different cases. If the DropDownStyle is DropDown (i.e. drop/edit), set the Text property to have an initial value. If it is DropDownList, set SelectedIndex (or SelectedItem). You should do this after InitialiseComponent is called; I typically do it lower down in the form class constructor. Alternatively, if you data bind the combos, they will initialise to the initial value of the property to which they are bound.

            1 Reply Last reply
            0
            • S sarang_k

              Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.

              A Offline
              A Offline
              ambarishtv
              wrote on last edited by
              #6

              this code may help you.. ;)

              private void loadComboBox()
              {
              if (this.cmb.DataSource == null)
              {
              this.cmb.Items.Add("Please Wait");
              this.cmb.Text = "Please Wait";
              this.cmb.Refresh();
              }

                      DataTable tbl = comboData() as DataTable;
                      tbl.Rows.Add(0, "");
                      cmb.DataSource = tbl;
                      cmb.DisplayMember = "Name";
                      cmb.ValueMember = "Id";
                      cmb.SelectedValue = 0;
                  }
              

              -ambarish-

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups