WinForms DataGridView设置DataGridViewComboBoxCell值

时间:2015-04-06 12:16:32

标签: winforms datagridview datagridviewcomboboxcell

我有一个带有自定义DataGridViewComboBoxCell列的DataGridView,我运行以下代码将其单元初始化为我想要的初始值:

            try
            {
                this.dgvTemplatesConfiguration.Columns.Add(this.CreateFaultsColumn(faultsData, "OuterFaults", 2));
                this.dgvTemplatesConfiguration.Columns.Add(this.CreateFaultsColumn(faultsData, "InnerFaults", 5));

            }
            catch (Exception ex)
            {
                Log.WriteLineIf(ex.Message, TraceLevel.Info);
                throw;
            }

            for (int i = 0; i < dgvTemplatesConfiguration.Rows.Count - 1; i++)
            {
                dgvTemplatesConfiguration["InnerFaults", i].Value = OkFaultName;
                dgvTemplatesConfiguration["OuterFaults", i].Value = OkFaultName;
            }

如果我在OnLoad事件上执行此操作,代码工作正常并进入单元格,但如果我之后在OnVisibleChanged事件上运行它,我会得到一个异常

DataGridViewComboBoxCell value is not valid

DataGridViewComboBoxCell上设置默认值的正确方法是什么?

0 个答案:

没有答案