DataGridViewButtonColumn.UseColumnTextForButtonValue 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,指示 Text 属性值是否显示为此列中单元格的按钮文本。
public:
property bool UseColumnTextForButtonValue { bool get(); void set(bool value); };
public bool UseColumnTextForButtonValue { get; set; }
member this.UseColumnTextForButtonValue : bool with get, set
Public Property UseColumnTextForButtonValue As Boolean
属性值
如果 Text 属性值显示在列中的按钮上,则为 true
;如果每个单元格的 FormattedValue 属性值都显示在它的按钮上,则为 false
。 默认值为 false
。
例外
CellTemplate 属性的值为 null
。
示例
下面的代码示例演示了此属性的使用。
private void CreateUnboundButtonColumn()
{
// Initialize the button column.
DataGridViewButtonColumn buttonColumn =
new DataGridViewButtonColumn();
buttonColumn.Name = "Details";
buttonColumn.HeaderText = "Details";
buttonColumn.Text = "View Details";
// Use the Text property for the button text for all cells rather
// than using each cell's value as the text for its own button.
buttonColumn.UseColumnTextForButtonValue = true;
// Add the button column to the control.
dataGridView1.Columns.Insert(0, buttonColumn);
}
Private Sub CreateUnboundButtonColumn()
' Initialize the button column.
Dim buttonColumn As New DataGridViewButtonColumn
With buttonColumn
.HeaderText = "Details"
.Name = "Details"
.Text = "View Details"
' Use the Text property for the button text for all cells rather
' than using each cell's value as the text for its own button.
.UseColumnTextForButtonValue = True
End With
' Add the button column to the control.
dataGridView1.Columns.Insert(0, buttonColumn)
End Sub
注解
默认情况下, DataGridViewCell.FormattedValue 按钮单元格显示为按钮上的文本。 该 UseColumnTextForButtonValue 属性允许设置每个单元格的按钮文本,或者对所有按钮单元格使用 Text 属性值。
获取或设置此属性获取或设置 UseColumnTextForButtonValue 属性返回 CellTemplate 的对象的属性。 设置此属性还会设置 UseColumnTextForButtonValue 列中每个单元格的属性,并刷新列显示。 若要替代单个单元格的指定值,请设置列值后设置单元格值。