Click here to Skip to main content
14,880,638 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";
to
orbStyleRibbonComboBox.SelectedIndex == "blablabla";
and
orbStyleRibbonComboBox.SelectedIndex = 'blablabla';
but I can't...
Posted
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

C#
orbStyleRibbonComboBox.SelectedText = "blablabla";
   
v2
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:
C#
orbStyleRibbonComboBox.SelectedIndex = 0;
Or
C#
orbStyleRibbonComboBox.SelectedIndex = i + 3;


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

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