【问题标题】:Unable to edit cell in DataGridView无法在 DataGridView 中编辑单元格
【发布时间】:2021-04-20 02:44:49
【问题描述】:

我有一个尝试手动编辑的 DataGridView。

-grid.ReadOnly 为假
-所有列只读为假
-EditMode 是 OnKeyStroke
- 不受任何约束
- 无数据验证

如果我在网格中输入一个值,然后按回车键或单击另一个单元格,输入的值就会消失。

我在 DataGridView 上设置了以下事件:
细胞鼠标双击

private void trackEditor_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridView grid = sender as DataGridView;
            //checks if the cell's value contains a 0. If so, change the value to write to 1. If not, assume the cell value is already 0 and keep the value to write to 0
            int val;
            if (grid.CurrentCell.Value == null || int.Parse(grid.CurrentCell.Value.ToString()) == 0)
                val = 1;
            else 
                val = 0;
            grid.CurrentCell.Value = val;
        }

CellValue 改变

private void trackEditor_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string _out = "";
            for (int x = 0; x < trackEditor.ColumnCount; x++) {
                if (trackEditor.CurrentRow.Cells[x].Value != null)
                    _out += x + ":" + trackEditor.CurrentRow.Cells[x].Value + ",";
            }
            richRawTrackData.Text = _out;
        }

【问题讨论】:

  • 绑定什么?你在使用验证吗?订阅了其他活动吗?请将您认为相关的任何代码edit 添加到您的帖子中
  • 更新帖子@Charlieface
  • 这是针对每一列还是仅针对某些列? column.ValueTypeFormattedValueType 是什么?还有其他奇怪的设置吗?
  • 每列和单元格似乎都受到了影响。 ValueType 是字符串。我没有设置FormattedValueType
  • richRawTrackData.Text 中看不到编辑后的值?

标签: c# winforms


【解决方案1】:

我找到了答案。通过创建一个重复的 DGV 并一一比较 Properties,我发现是 VirtualMode 属性阻止了输入数据。将其设置为 false 允许现在输入数据。

【讨论】:

    猜你喜欢
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多