GridColumn (Column Layout and Auto Width)

Namespace:DevExpress.XtraGrid.Columns
Assembly:DevExpress.XtraGrid.v16.2.dll

https://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraGridColumnsGridColumntopic

Represents an individual column in Grid Views and Card Views.

Remarks

GridColumn objects represent columns and card fields in Grid Views and Card Views respectively. Such objects are used to display data from an individual data field. The bound data field is specified by the FieldName property. Settings provided by the GridColumn class also allow you to control how column data is displayed and edited, column header contents, the column's position and visibility, etc.

Note that some of the settings provided are in effect only for columns displayed in Grid Views.

For instance, the GroupIndex and SummaryItem properties are in effect for Grid View columns only, as Card Views do not support the grouping and summary features.

You can access a View's column collection using the ColumnView.Columns property. This property returns an object whose indexer can be used to access individual GridColumn objects. Note also that column objects are Component descendants. This enables you to access columns in code directly by their names.

You don't need to create column objects manually using the GridColumn class constructor. Columns can be created using methods of the owning column collection (GridColumnCollection class) or by using the ColumnView.PopulateColumns method of the required View.

For additional information regarding columns, refer to the Column and Card Field OverviewCreating Columns and Binding Them to Data Fields and Accessing and Identifying Columns topics.

ColumnLayout

列长自适应

https://documentation.devexpress.com/#WindowsForms/CustomDocument649

设置GridView的OptionsView的ColumnAutoWidth属性为True

FixedStyle枚举类型

https://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridColumnsFixedStyleEnumtopic

Left The band or column is anchored to the View's left edge.

None The band or column takes part in horizontal scrolling.

Right The band or column is anchored to the View's right edge.

用来固定某一列的位置,上面的链接里有相关说明

Best Fit

Grid Views allow you to apply the best fit feature to an individual column and to all columns at once. When the feature is applied to a column, column width is changed to fit its content (subject to the minimum width restriction). By default, all column values are processed and column width is set to the maximum width required by any cell. For performance reasons, you can limit the number of records taken into account when applying the best fit feature by setting the View's GridOptionsView.BestFitMaxRowCount property. By default, this property value is -1 to indicate that all data rows will be processed. If set to a positive integer, the View processes the specified number of data rows starting from the top visible row.

End-users can apply best fit to a column or to all columns at once using the column header panel's popup menu. Please refer to the Popup Menus Overview topic for details. You can also apply the feature in code using the View's GridView.BestFitColumns method or a column's GridColumn.BestFit method.

Applying best fit with auto width enabled requires special attention. As stated above, the total width of columns always equals the View's width. Thus, applying best fit may not display complete cell contents if the View is not wide enough. On the other hand, columns may be wider than their contents require. A columns' required size is calculated and proportionally applied, so that the total width is the View's width. The image below illustrates an example.

FixedWidth

You can force a column to have a fixed width. Enable a column's OptionsColumn.FixedWidth option for this purpose.

If the option is enabled, a column's width is not affected by the auto width and best fit features.

End-users can resize columns regardless of this option setting.

To prohibit column resizing, use the column's OptionsColumn.AllowSize option.

https://documentation.devexpress.com/#WindowsForms/CustomDocument114719

https://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridColumnsGridColumn_Fixedtopic

设置GridView的OptionsView的ColumnAutoWidth属性为False

设置GridColumn的Fixed属性为Left,设置Width为固定值

原文地址:https://www.cnblogs.com/chucklu/p/6419114.html