DataGridView.IsCurrentCellInEditMode 属性

定义

获取一个值,该值指示是否正在编辑当前处于活动状态的单元格。

C#
[System.ComponentModel.Browsable(false)]
public bool IsCurrentCellInEditMode { get; }

属性值

如果正在编辑当前单元格,为true ;否则为 false

属性

示例

下面的代码示例演示如何使用此属性。 此示例是参考主题中提供的更大示例的 VirtualMode 一部分。

C#
#region "data store maintance"
const int initialValue = -1;

private void dataGridView1_CellValueNeeded(object sender,
    DataGridViewCellValueEventArgs e)
{
    if (store.ContainsKey(e.RowIndex))
    {
        // Use the store if the e value has been modified 
        // and stored.            
        e.Value = store[e.RowIndex];
    }
    else if (newRowNeeded && e.RowIndex == numberOfRows)
    {
        if (dataGridView1.IsCurrentCellInEditMode)
        {
            e.Value = initialValue;
        }
        else
        {
            // Show a blank value if the cursor is just resting
            // on the last row.
            e.Value = String.Empty;
        }
    }
    else
    {
        e.Value = e.RowIndex;
    }
}

private void dataGridView1_CellValuePushed(object sender,
    DataGridViewCellValueEventArgs e)
{
    store.Add(e.RowIndex, int.Parse(e.Value.ToString()));
}
#endregion

private Dictionary<int, int> store = new Dictionary<int, int>();

注解

DataGridViewCheckBoxCell具有焦点的 始终处于编辑模式的 。 如果当前单元格承载编辑控件且 IsCurrentCellInEditModetrue,则可以通过 属性检索编辑控件 EditingControl

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅