3

I have a combo box, filled with different kind of human muscles like "chest", "back", etc. The problem is that the default selected item is "chest" I guess because its the first one on the List, but how can I change that to my costume text, which is not in the list with muscles.

Here is a screenshot for better preview of the problem:

enter image description here

private void Form1_Load(object sender, EventArgs e)
{
    AddItems(primaryMuscleBox, primaryMuscles);
    AddItems(secondaryMuscleBox, secondaryMuscles);

    primaryMuscleBox.SelectedItem = "please choose a primary muscle";
}

private void AddItems(MetroComboBox comboBox, List<string> name)
{
    comboBox.DataSource = null;
    comboBox.DataSource = name;
}

private List<string> primaryMuscles = new List<string>()
{
    "Chest",
    "Back",
    "Legs",
    "Shoulders"
};

EDIT: I am using MetroComboBox, not the standard one.

Brendon
  • 334
  • 1
  • 2
  • 14
  • Add it to the list first. comboBox.SelectedIndex < 1 means the user didn't make a selection. – LarsTech May 06 '16 at 15:03
  • Otherwise, see [ComboBox Cue Banner not italic when DropDownStyle is DropDown](http://stackoverflow.com/a/8904184/719186) – LarsTech May 06 '16 at 15:16

1 Answers1

0

try this with a Standard ComboBox - comboBox1.Text = "Please Select a muscle";

Brendon
  • 334
  • 1
  • 2
  • 14
  • Do you know how when you're making an account somewhere, on the username box it says "Enter your username here" and when you start typing it disappears ? I want to make it something like this here, instead of showing the first muscle on the List I want to put my own text there like "Choose your primary muscle." and when you choose something it replaces it with the muscle you have chosen. – Денислав Ангелов May 06 '16 at 15:09
  • You can go into the Properties of the comboBox and put the Text as "Choose your primary muscle" and when you run the code and choose your muscle then it will remove that text – Brendon May 06 '16 at 15:11
  • The comboBox doesn't have the text property. Anyways I tried to do it manually with comboBox.Text = "Choose your primary muscle" and it still doesn't work. – Денислав Ангелов May 06 '16 at 15:14
  • not sure why? Are you using a different from standard comboBox? if that is possible? – Brendon May 06 '16 at 15:15
  • Oh, actually yeah. I am using a MetroComboBox. – Денислав Ангелов May 06 '16 at 15:16
  • I have Visual Studio open and have a comboBox on a form and it has a Text property... Just to confirm, you are using C#, Windows Forms in Visual Studio, if so which version of C# and Visual Studio – Brendon May 06 '16 at 15:17
  • Ok, I havent use the metro combobox before so i dont know about that, and i cant seem to find it – Brendon May 06 '16 at 15:18
  • Yes, I checked it myself. The standard comboBox does have a Text property but I am using MetroComboBox. Its something like a theme I found. – Денислав Ангелов May 06 '16 at 15:18
  • That may be your issue then, it would be worth probably change it to a standard ComboBox, that is a personal opinion, please only do so if you want to – Brendon May 06 '16 at 15:20
  • 1
    @ДениславАнгелов You need to document your question that you are using that 3rd party library. – LarsTech May 06 '16 at 15:21
  • @dur I have undeleted and edited to fit an answer without the comment that should have been in the initial question – Brendon May 11 '16 at 08:27