DataGridViewColumnCollection.GetColumnsWidth(DataGridViewElementStates) DataGridViewColumnCollection.GetColumnsWidth(DataGridViewElementStates) DataGridViewColumnCollection.GetColumnsWidth(DataGridViewElementStates) DataGridViewColumnCollection.GetColumnsWidth(DataGridViewElementStates) Method

정의

지정된 필터 요구 사항을 충족시키는 모든 열을 표시하는 데 필요한 너비(픽셀)를 반환합니다.Returns the width, in pixels, required to display all of the columns that meet the given filter requirements.

public:
 int GetColumnsWidth(System::Windows::Forms::DataGridViewElementStates includeFilter);
public int GetColumnsWidth (System.Windows.Forms.DataGridViewElementStates includeFilter);
member this.GetColumnsWidth : System.Windows.Forms.DataGridViewElementStates -> int
Public Function GetColumnsWidth (includeFilter As DataGridViewElementStates) As Integer

매개 변수

includeFilter
DataGridViewElementStates DataGridViewElementStates DataGridViewElementStates DataGridViewElementStates

포함 필터를 나타내는 DataGridViewElementStates 값의 비트 조합입니다.A bitwise combination of the DataGridViewElementStates values that represent the filter for inclusion.

반환

필터 요구 사항을 충족시키는 모든 열을 표시하는 데 필요한 너비(픽셀)입니다.The width, in pixels, that is necessary to display all of the columns that meet the filter requirements.

예외

includeFilterDataGridViewElementStates 값의 유효한 비트 조합이 아닌 경우includeFilter is not a valid bitwise combination of DataGridViewElementStates values.

예제

다음 코드 예제에서는이 메서드의 사용을 보여 줍니다.The following code example illustrates the use of this method. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부 방법: Windows Forms DataGridView 컨트롤에서 행 모양 사용자 지정합니다.This example is part of a larger example available in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Paints the custom selection background for selected rows.
void dataGridView1_RowPrePaint(object sender,
        DataGridViewRowPrePaintEventArgs e)
{
    // Do not automatically paint the focus rectangle.
    e.PaintParts &= ~DataGridViewPaintParts.Focus;

    // Determine whether the cell should be painted
    // with the custom selection background.
    if ((e.State & DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
    {
        // Calculate the bounds of the row.
        Rectangle rowBounds = new Rectangle(
            this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
            this.dataGridView1.Columns.GetColumnsWidth(
                DataGridViewElementStates.Visible) -
            this.dataGridView1.HorizontalScrollingOffset + 1,
            e.RowBounds.Height);

        // Paint the custom selection background.
        using (Brush backbrush =
            new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
                this.dataGridView1.DefaultCellStyle.SelectionBackColor,
                e.InheritedRowStyle.ForeColor,
                System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(backbrush, rowBounds);
        }
    }
}
' Paints the custom selection background for selected rows.
Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPrePaintEventArgs) _
    Handles dataGridView1.RowPrePaint

    ' Do not automatically paint the focus rectangle.
    e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus

    ' Determine whether the cell should be painted with the 
    ' custom selection background.
    If (e.State And DataGridViewElementStates.Selected) = _
        DataGridViewElementStates.Selected Then

        ' Calculate the bounds of the row.
        Dim rowBounds As New Rectangle( _
            Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
            Me.dataGridView1.Columns.GetColumnsWidth( _
            DataGridViewElementStates.Visible) - _
            Me.dataGridView1.HorizontalScrollingOffset + 1, _
            e.RowBounds.Height)

        ' Paint the custom selection background.
        Dim backbrush As New _
            System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
            Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
            e.InheritedRowStyle.ForeColor, _
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(backbrush, rowBounds)
        Finally
            backbrush.Dispose()
        End Try
    End If

End Sub

적용 대상

추가 정보