【问题标题】:How DataGridViewCellEventArgs helps to modify current value from a DataGridViewCell?DataGridViewCellEventArgs 如何帮助修改 DataGridViewCell 的当前值?
【发布时间】:2009-05-09 01:58:00
【问题描述】:

当 CheckBoxColumn 已被检查时,我正在使用此事件来备注该行,所以另外我想使用“Value”属性“以编程方式”替换同一行中的当前单元 [6] 值,但它失败了因为默认情况下“readOnly”属性是=“true”。

DataGridView1.DataSource 是从 LINQ2SQL 查询中检索到的。

void updateStyle_DataGridViewCellEventArgs(object sender, DataGridViewCellEventArgs e)
{
     if (e.RowIndex == -1)
         return;
     else
     {
        DataGridView dgv = sender as DataGridView;
        int vCHK = e.ColumnIndex;
        if (vCHK != 0)
            return;
        else
        {
            DataGridViewCheckBoxCell temp = (DataGridViewCheckBoxCell)dgv.Rows[e.RowIndex].Cells[0];
            if ((bool)temp.EditedFormattedValue == true)
            {
                DataGridViewTextBoxCell xrow = (DataGridViewTextBoxCell)dgv.Rows[e.RowIndex].Cells[6];
                xrow.ReadOnly = false;
                xrow.Value = "P";
                xrow.OwningRow.DefaultCellStyle.BackColor = Color.Wheat;
            }
            else
            {
                temp.OwningRow.DefaultCellStyle.BackColor = Color.White;
            }
        }
    }
}

【问题讨论】:

    标签: c# events datagridview


    【解决方案1】:

    我会在 DataSource 中找到实际的对象/行,翻转那里的布尔值,然后重新绑定网格。然后可以在 CellFormatting 事件中设置 BackColor。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多