我想启用特定的单元格进行编辑。
我的datagridview只读为false。
并在单元格上单击,我得到我的columnindex并尝试执行:
if (e.ColumnIndex == 7)
{
if (String.IsNullOrEmpty(Convert.ToString(dgv.Rows[e.RowIndex].Cells["id"].Value)))
{
dgv.Columns[e.ColumnIndex].ReadOnly = true;
}
else
{
dgv.Columns[e.ColumnIndex].ReadOnly = false;
dgv.BeginEdit(true);
dgv.Rows[rowindex].Cells[columnindex].Selected = true;
}
}
没有成功,我的手机保持禁用状态。有人可以帮忙。谢谢
我用这段代码解决了我的问题:
private void dgvLocataire_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
dgvLocataire.BeginEdit(false);
var ec = dgvLocataire.EditingControl as DataGridViewComboBoxEditingControl;
if (ec != null && ec.Width - e.X < SystemInformation.VerticalScrollBarWidth)
ec.DroppedDown = true;
if ((e.ColumnIndex != 5) && (e.ColumnIndex != 6) && (e.ColumnIndex != 7))
{
dgvLocataire.Columns[e.ColumnIndex].ReadOnly = true;
}
}
感谢您的帮助