Compartir a través de


Grid Highlighting, Column Resizing, and Header Images Sample

File: ...\Samples\Solution\Toledo\Griders.scx

This sample demonstrates how you can perform the following actions:

  • Select style and colors for grid highlighting.
  • Resize columns automatically to the width of data in the column.
  • Lock the first grid column so that it does not scroll.
  • Specify images in column headers.

Selecting Grid Highlight Styles

You can use highlighting styles to control how highlighting appears and behaves in a grid when you select rows and the focus moves from the grid. To set highlighting styles, use the GridHighlightStyle property.

In the sample, to set the HighlightStyle, select a style in the combo box on the form. The combo box contains the following code:

ThisForm.grdCustomers.HighlightStyle = VAL(this.Value)

For more information about HighlightStyle, see HighlightStyle Property.

You can also set highlighting colors. For more information, see HighlightBackColor Property, HighlightForeColor Property, SelectedItemBackColor Property, and SelectedItemForeColor Property.

Fitting Columns to Width of Data

This sample resizes grid columns automatically to fit the width of data in the column using the GridAutoFit method as follows:

ThisForm.grdCustomers.AutoFit() 

You can also resize grid columns by double-clicking the upper-left corner of the grid. To resize an individual column automatically, double-click the dividing line on right side of the column. You can control this behavior using the GridAllowAutoColumnFit property.

For more information, see AutoFit Method and AllowAutoColumnFit Property.

Locking Grid Columns

You can lock columns so the columns remain fixed when the scrolling horizontally across a grid by using the GridLockColumns property.

In the sample, you can lock the first column in the grid by setting grdCustomers.LockColumns to 1 as in the following code:

ThisForm.grdCustomers.LockColumns = 1

You can also lock the Customer ID column by clicking the column header. The pushpin in the column header indicates whether the column is locked. To lock individual columns, right-click the area between the column headers.

For more information, see LockColumns Property and LockColumnsLeft Property.

Displaying Images in Column Headers

You can specify an image for a column header using the Picture property and set image orientation using the HeaderAlignment property.

In the sample, an image appears in the Company Name column header to indicate the direction of the sort order in the column. Clicking the column header displays different images to indicate ascending or descending sort order.

For more information, see Picture Property and Alignment Property.

See Also

Solutions Samples | Customizing a Browse Window