Click here to Skip to main content
15,747,845 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I want to select the combo box by clicking the button like this

orbStyleRibbonComboBox.SelectedIndex = "blablabla";

However, the error
CS0029 Cannot implicitly convert type 'string' to 'int'
showed up. I have no idea why.

What I have tried:

Try changing
orbStyleRibbonComboBox.SelectedIndex = "blablabla";
orbStyleRibbonComboBox.SelectedIndex == "blablabla";
orbStyleRibbonComboBox.SelectedIndex = 'blablabla';
but I can't...
Updated 16-Oct-20 1:26am

SelectedIndex is an int, it represents the index of the item to select so 0 for first, 1 for second etc so you can't assign a string to it. If you want to select based on the text value use

orbStyleRibbonComboBox.SelectedText = "blablabla";
Share this answer
The ComboBox.SelectedIndex property[^] is an int value - you cannot assign any string (even one containing a number like "123") to it. Only integers are allowed:
orbStyleRibbonComboBox.SelectedIndex = 0;
orbStyleRibbonComboBox.SelectedIndex = i + 3;

Have you considered the ComboBox.SelectedText Property[^] instead?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900