我将DataGridView的AutoSizeColumnModes属性设置为AllCells,但在用户完成编辑单元格之前,该列实际上并未实际调整大小。我尝试使用单元格的EditingControl的KeyPress事件来调用DataGridView的AutoResizeColumns()方法,但这并不起作用。
答案 0 :(得分:0)
是的,通过编写CurrentCellDirtyStateChanged
事件脚本来在键入时立即提交编辑:
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange);
}