简体   繁体   English

更改 DataGridView 按钮文本 windows 表单

[英]Changing DataGridView button text windows form

I have a button inside DataGridView as:我在DataGridView中有一个按钮:

  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.如您所见,我有UseColumnTextForButtonValue = true因为我想在之后更改文本。 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'无法将类型“System.Windows.Forms.DataGridViewCell”转换为“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)如何访问 Text 属性转换,例如: DataGridViewDisableButtonCell (这没有 Text 属性,但我可以在 foreach 中使用 select 行)

Set the property of a column that is a button to UseColumnTextForButtonValue = false;将作为按钮的列的属性设置为UseColumnTextForButtonValue = false; Adjust it in DataGridView在 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按照此链接设置UseColumnTextForButtonValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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