C# – How To Set Selected Item In Combobox

-- Sponsered Links --

C# – How To Set Selected Item In Combobox




The same question is applicable for all other dot net (.NET) languages. The question could be rephrased as:

  • How to set selected item in combobox
  • ComboBox.SelectedItem Property (System.Windows.Forms)
  • How to set the default selected item in the ComboBox (C#, winform
  • set selected index of a ComboBox – bytes
  • C# .NET ComboBox selected item question

When populating a combobox on form load with an arraylist that contains objects of the type ABC Now after combobox is filled with the valid values, I want to have the combobox in C# change the selected item to be a specific ABC object, how do I accomplish it ?You can select the combobox item by its ValueMember

You can use:
combo1.SelectedValue = YourValue

This will select  the item with the value "YourValue"

combo1.SelectedValue = YourValue ABC abc1 = (ABC) combo1.SelectedItem

Combobox.FindByText(someText).Selected = true;

or

Combobox.FindByValue(someValue).Selected = true;

Use the first if you want the text displayed in the combobox to find the item you want selected, use the second if you want to use the items value (mostly the ID).

Combobox.FindByText(someText).Selected = true;

or

Combobox.FindByValue(someValue).Selected = true;

Use the first if you want the text displayed in the combobox to find the item you want selected, use the second if you want to use the items value (mostly the ID).

or

See This:
abc1.SelectedIndex = x;
where x = numbe of the item in the list.

or else
abc1.SelectedText = string;
where string = value in the combobox that you want to be selected

Related Posts:

  • No Related Posts

-- Sponsered Links --

Comments are closed.