Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two indexes on my combobox.

I want to take only the first index ?

Can I get some example ?

The code:

              foreach (DataRow dr2 in dt2.Rows)
            {
                comboBox1.Items.Add(dr2["Station"].ToString() + " - " + dr2["Ime"].ToString());
            }

I want to take dr2["Station"].ToString() ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
173 views
Welcome To Ask or Share your Answers For Others

1 Answer

The Win Forms ComboBox has both a SelectedIndex and SelectedText property.

Once your list is loaded with items you can pick which one is selected like this:

// selected by position in the list
comboBox1.SelectedIndex = 0;

// ... by value
comboBox1.SelectedText = "some value";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...