Search code examples
c#combobox

C# Compare Combobox Member Value with string


I want to compare the string with Combobox Member Values. If string value matched, I need the index of matched value as well.


Solution

  • possibly this will help you.

    private void SampleMethod()
    {
        cboExample.Items.AddRange(new string[]
        {
            "Element 1", "Element 2", "Element 3", "Element 4"
        });
    
        string searchedText = "Element 3";
        int index = cboExample.FindString(searchedText);
        MessageBox.Show($"Index of \"{searchedText}\" is {index}");
    }