【发布时间】: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.ValueType和FormattedValueType是什么?还有其他奇怪的设置吗? -
每列和单元格似乎都受到了影响。
ValueType是字符串。我没有设置FormattedValueType -
在
richRawTrackData.Text中看不到编辑后的值?