The comboBox9 gets populated with unique values from an Excel Range with the code below.
comboBox9.Items.Clear();
HashSet<string> distinct = new HashSet<string>();
foreach (_Excel.Range cell in range.Cells)
{
string value = (cell.Value2).ToString();
if (distinct.Add(value))
comboBox9.Items.Add(value);
}
What i tried to do unsuccessfully is set the index of the combobox9 with the first item that satisfies the if condition .
foreach (string item in comboBox9.Items)
{
if (278 * Variables.m3h / (Math.Pow(int.parse(item) / 2, 2) * 3.14) > Variables.maxvelocity)
{
comboBox9.SelectedIndex = comboBox9.Items.IndexOf(item);
}
}
Any ideas on where i'm going wrong ?