Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, add a Form_Load Event and put your code in the handler. (use constructor for property initialization and other variable initialization) </p> <pre><code>private void Form1_Load(object sender, EventArgs e) { this.comboBox1.SelectedItem= 5; // This will set the combo box to index 5 string cpuCount = this.comboBox1.SelectedText; // This will get the text of the selected item } </code></pre> <p>so you get the value of item at index 5 in <code>cpuCount</code> variable.</p> <p>The <code>selected</code> clause gives you the values AFTER you have selected something, by default(when you run your app) there is nothing selected in the comoboBox, hence, it displays the value as null, after selecting the item you can use the combobox's selectedItem, selectedIndex, selectedText and selectedValue properties.</p> <p>You can also use databinding to display items in the combobox, which in my view is a better way then adding the items manually. </p> <p>to databind your combobox you can use,</p> <pre><code>// Bind your combobox to a datasource, datasource can be a from a database table, List, Dataset, etc.. IDictionary&lt;int, string&gt; comboDictionary = new Dictionary&lt;int, string&gt;(); comboDictionary.Add(1, "first"); comboDictionary.Add(2, "second"); comboDictionary.Add(3, "third"); comboBox1.DataSource = comboDictionary; comboBox1.DisplayMember = "Key"; comboBox1.ValueMember = "Value"; // </code></pre> <p>And here now you can use combobox1.SelectedIndex to go through the item collection in the datasource :) and it will give you the value against your keys when you use combobox1.SelectedValue. Hope this helps. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload