DataGridViewColumn.Width DataGridViewColumn.Width DataGridViewColumn.Width DataGridViewColumn.Width Property

定義

取得或設定目前的資料行寬度。Gets or sets the current width of the column.

public:
 property int Width { int get(); void set(int value); };
public int Width { get; set; }
member this.Width : int with get, set
Public Property Width As Integer

屬性值

資料行的寬度 (以像素為單位)。The width, in pixels, of the column. 預設值為 100。The default is 100.

例外狀況

設定這個屬性時指定的值大於 65,536。The specified value when setting this property is greater than 65536.

範例

下列程式碼範例會設定資料行的寬度。The following code example sets the width of a column. 這個程式碼範例是針對DataGridViewColumn類別提供之較大範例的一部分。This code example is part of a larger example provided for the DataGridViewColumn class.

// Set the width.
void Button5_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   DataGridViewColumn^ column = dataGridView->Columns[ 0 ];
   column->Width = 60;
}


// Set the width.
private void Button5_Click(object sender, System.EventArgs e)
{
    DataGridViewColumn column = dataGridView.Columns[0];
    column.Width = 60;
}
' Set the width.
Private Sub Button5_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button5.Click

    Dim column As DataGridViewColumn = dataGridView.Columns(0)
    column.Width = 60
End Sub

備註

如果設定這個屬性時所指定的值小於MinimumWidth屬性的值MinimumWidth ,則會改用屬性值。If the specified value when setting this property is less than the value of the MinimumWidth property, the MinimumWidth property value is used instead.

適用於

另請參閱