如何在C#中的datagridview中使datagridview的某些行只读和其他可编辑

时间:2018-10-01 12:20:48

标签: c# winforms datagridview

我有一个包含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。但这没有用。

我的datagridview包含我想不可编辑的现有数据,但是当用户向最后一行写入内容时,它必须是可编辑的。    enter image description here

0 个答案:

没有答案