简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM