datagird抛出可重入调用异常

时间:2018-08-24 09:22:38

标签: c# winforms datagrid

        void dgvParameters_RowLeave(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
                return;

            Control[] l_ControlList = this.Controls.Find("cmbManual_" + e.RowIndex, true);
            PresentationControls.CheckBoxComboBox l_ComboBox = (PresentationControls.CheckBoxComboBox)l_ControlList.FirstOrDefault();
            if (l_ComboBox == null)
            {
                return;
            }
            l_ComboBox.Hide();

            DataGridViewTextBoxCell l_objMouseRep = new DataGridViewTextBoxCell();

            l_objMouseRep.Value = Convert.ToString(l_ComboBox.SelectedItem);
            if (dgvParameters != null && dgvParameters.Rows.Count > 0)
                dgvParameters[2, e.RowIndex] = l_objMouseRep;
        } 

两次调用Datagridview rowleave事件会导致此行代码dgvParameters [2,e.RowIndex] = l_objMouseRep;重新出现问题。

抛出异常: System.InvalidOperationException:操作无效,因为它导致对SetCurrentCellAddressCore函数的可重入调用。    在System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex,Int32 rowIndex,布尔setAnchorCellAddress,布尔validateCurrentCell,布尔throughMouseClick

0 个答案:

没有答案