我有一个包含datagrid视图的winform,其中包含一些数据,这些数据在我运行我的应用程序时加载,但是假设在运行过程中,用户可以向此datagridview添加新行,但无法编辑datagridview的现有条目,然后如何做到这一点。
我尝试将列的readonly属性设置为true,但是这使所有内容均不可编辑,我也尝试过此操作:-
foreach (KeyValuePair<string, string> entry in cevnt.Properties)
{
DataGridViewComboBoxCell propertyType1 = new DataGridViewComboBoxCell();
DataGridViewTextBoxCell propertyName1 = new DataGridViewTextBoxCell();
propertyName1.Value = entry.Key.ToString();
propertyName1.ReadOnly = true; int index =
propertyTypeList.IndexOf(entry.Value.ToString());
propertyType1.Items.AddRange(propertyTypeList);
if(index != -1)
{
propertyType1.DisplayMember = propertyTypeList[index];
}
else
{
propertyType1.DisplayMember = string.Empty;
}
customEventPropertiesDgv.Rows.Add(entry.Key.ToString());
customEventPropertiesDgv.Rows[rowIndex].Cells[1] = propertyType1;
customEventPropertiesDgv.Rows[rowIndex].Cells[0].ReadOnly = true;
}
在这里,我将单个单元格的readonly属性设置为true。但这没有用。