0

I have a button inside DataGridView as:

  var dgvButCol = new DataGridViewDisableButtonColumn()
            {
                Name = "btnSetContact",
                Text = "Set Contact",
                HeaderText = "Set",
                UseColumnTextForButtonValue = true
            };

As you see, I have UseColumnTextForButtonValue = true because I want to change the text after. In order to change it I try:

  foreach (DataGridViewRow row in dgvDeliveryBreakdownDesignGroup.Rows)
            {
                bool.TryParse(row.Cells["HaveDeliveryContact"].Value.ToString(), out bool haveDeliveryContact);

                if (haveDeliveryContact || lblDeliveryContactName.Text == "None")
                {
                   
                    ((DataGridViewDisableButtonColumn)row.Cells["btnSetContact"]).Text = "gg";

                }

}

But it throws an error:

Cannot convert type 'System.Windows.Forms.DataGridViewCell' to 'MyProjectName.Controls.DataGridViewDisableButtonColumn'

How can I access Text property casting something like: DataGridViewDisableButtonCell (this do not have Text property but I can select row inside foreach)

Jesus
  • 331
  • 1
  • 4
  • 19
  • Yes, the exception is clear, you are doing a wrong cast. Also, not clear if you want to change the `Value` of a single or some buttons or all of them. All buttons will display what you assigned to the `Text` property when you enable the `UseColumnTextForButtonValue` property. So, what are you trying to do here? – dr.null Nov 24 '21 at 00:23

1 Answers1

1

Set the property of a column that is a button to UseColumnTextForButtonValue = false; Adjust it in DataGridView

foreach (DataGridViewRow row in dgvDeliveryBreakdownDesignGroup.Rows)
{
   DataGridViewButtonCell buttonCell = (DataGridViewButtonCell)row.Cells[0];
   buttonCell.Value = "button row " + row.Index;
}

Follow this link to set UseColumnTextForButtonValue

Meysam Asadi
  • 6,438
  • 3
  • 7
  • 17