共用方式為


DataGridViewButtonColumn.UseColumnTextForButtonValue 屬性

定義

取得或設定值,指出 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

屬性值

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 資料行中每個儲存格的 屬性,並重新整理資料行顯示。 若要覆寫個別儲存格的指定值,請在設定資料行值之後設定儲存格值。

適用於

另請參閱