Jesus
Jesus

Reputation: 485

Changing DataGridView button text windows form

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)

Upvotes: 0

Views: 286

Answers (1)

persian-theme
persian-theme

Reputation: 6638

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

Upvotes: 1

Related Questions