Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


DataGridViewBand.Index Property

Definition

Gets the relative position of the band within the DataGridView control.

[System.ComponentModel.Browsable(false)]
public int Index { get; }

Property Value

The zero-based position of the band in the DataGridViewRowCollection or DataGridViewColumnCollection that it is contained within. The default is -1, indicating that there is no associated DataGridView control.

Attributes

Examples

The following code example uses the Index property to set column labels. The band's Index property is accessed through a DataGridViewColumn.

Megjegyzés

If visual styles are enabled, the current theme overrides the display style properties for row and column headers.

// Style and number columns.
private void Button8_Click(object sender,
    EventArgs args)
{
    DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.Alignment =
        DataGridViewContentAlignment.MiddleCenter;
    style.ForeColor = Color.IndianRed;
    style.BackColor = Color.Ivory;

    foreach (DataGridViewColumn column in dataGridView.Columns)
    {
        column.HeaderCell.Value = column.Index.ToString();
        column.HeaderCell.Style = style;
    }
}

Remarks

The value of this property does not necessarily correspond to the current visual position of the band within the collection. For example, if the user reorders columns in a DataGridView at run time (assuming the AllowUserToOrderColumns property is set to true), the value of the Index property of each column will not change. Instead, the column DisplayIndex values change. Sorting rows, however, does change their Index values.

Applies to

Termék Verziók
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also