我正在开发一个程序,它获取所有 Clearcase 区域(基本上是字符串)并将它们添加到组合框中。我比较了组合框中新添加的项目中现有的透明大小写区域字符串,如果找到它,那么我想选择它,但是因为第一次没有选择任何内容,所以 selectedItem 为 null & selectedIndex = -1。当我将 0 分配给 selectedIndex 时,错误来了 --> 对象未设置为对象的实例!!将某些内容分配给 selectedItem 时出现同样的问题;给出一个错误。
我的代码有什么问题?
    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;
    }