I am developing a program which gets all Clearcase regions (basically strings) & adds them to Combo box. I compare an existing clearcase region string in newly added items in combo box & if it is found then I want to select it, but because nothing is selected for the first time, selectedItem is null & selectedIndex = -1. when I assign 0 to selectedIndex, error comes --> object not set to instance of an object!! same problem when you assign something to selectedItem; gives an error.
whats wrong with my code?
private void PopulateClearCaseRegionComboBox ( )
{
clearCaseRegionComboBox.Items.Clear();
foreach ( Match token in RegularExpression.Match( "\\w+", clearTool.CmdExec( "lsregion" ) ) )
{
clearCaseRegionComboBox.Items.Add(token.Value.Trim());
if (clearCaseRegion.ToUpperInvariant() == token.Value.Trim().ToUpperInvariant())
{
clearCaseRegionComboBox.SelectedIndex = clearCaseRegionComboBox.Items.IndexOf(token.Value.Trim());
}
}
clearCaseRegionComboBox.Sorted = true;
}