DataGridColumn.DisplayIndex 屬性


取得或設定相對於 DataGrid 中之其他資料行的資料行位置。Gets or sets the display position of the column relative to the other columns in the DataGrid.

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


資料行之以零為起始的位置,如同關聯的 DataGrid 中所顯示。The zero-based position of the column, as it is displayed in the associated DataGrid. 已註冊的預設值為-1。The registered default is -1. 如需哪些因素會影響值的詳細資訊,請參閱 DependencyPropertyFor information about what can influence the value, see DependencyProperty.


屬性DisplayIndex在新增DataGrid.Columns至集合之前,預設值為-1。The DisplayIndex property has a default value of -1 before it is added to the DataGrid.Columns collection. 當資料行加入DataGrid時,就會更新這個值。This value is updated when the column is added to the DataGrid.

需要每個資料DisplayIndex行的屬性都必須是Columns從0到Count的唯一整數,也就是-1。 DataGridThe DataGrid requires that the DisplayIndex property of each column must be a unique integer from 0 to the Count of Columns -1. 因此,當某個DisplayIndex資料行的變更時,變更通常也DisplayIndex會導致其他資料行的變更。Therefore, when the DisplayIndex of one column changes, the change typically causes the DisplayIndex of other columns to also change.

DisplayIndex值的限制會ValidateValueCallback由機制強制執行。The restrictions on the DisplayIndex value are enforced by a ValidateValueCallback mechanism. 如果您嘗試設定的值無效,則會擲回執行時間例外狀況。If you attempt to set a value that is not valid, a run-time exception is thrown.

DisplayIndex屬性的值變更時DataGrid.ColumnDisplayIndexChanged ,就會引發事件。When the value of the DisplayIndex property is changed, the DataGrid.ColumnDisplayIndexChanged event is raised.