Datagridview, disable button/row

前端 未结 3 363
清歌不尽
清歌不尽 2020-12-07 02:16

I have a datagridview on a form with some data. The 1st column contains button for deleting the row. How can we disable this button or the entire row based on some condition

3条回答
  •  醉话见心
    2020-12-07 03:19

    Would you consider just turning the button cell into a regular empty text box disabled?

    Dim cell As DataGridViewButtonCell = dgv.row(x).cell(y)
    cell = New DataGridViewTextBoxCell()
    cell.value = String.Empty
    cell.ReadOnly = True
    

    It loses its bordered "Button" appearance and blends in with the remainder of the cells (assuming you are using primarily the default DataGridViewTextBoxCells).

    Here's the equivalent in C#, plus it grays out the field to make it look read-only:

    var cell = dgv[column, row] = new DataGridViewTextBoxCell();
    cell.Value = ""; // ignored if this column is databound
    cell.ReadOnly = true;
    cell.Style.BackColor = Color.FromKnownColor(KnownColor.Control);
    

提交回复
热议问题