Log In
[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Collapse]Grid View
    [Expand]Columns and Card Fields
    [Expand]Rows and Cards
    [Collapse]Row, Column and Cell Access API
      Tutorial: Identifying Rows
      Identifying Rows and Cards
      Accessing and Identifying Columns
    [Expand]Split Presentation
    [Expand]Cell Merging
    [Expand]Row Preview Sections
   [Expand]View Technology
   [Expand]Data Editing
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Report Server
[Expand]eXpressApp Framework
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Accessing and Identifying Columns

When working with XtraGrid, you may need to write code that accesses particular column properties or that passes column objects as method parameters, etc. You may also require column objects for event parameters or when obtaining hit information. This topic provides information on how to access and identify columns in code.

Expanded Accessing Columns

Column objects are Component class descendants. Thus, it is simple to access a column directly by its Name property. However, this feature is only available for columns created at design time. The code line below shows this approach, by changing a column's caption.

Column objects can also be accessed via a View's column collection (for Grid Views and Card Views, use the ColumnView.Columns property; for Layout Views, use the LayoutView.Columns property; for Banded Views, see the BandedGridView.Columns property; it's also possible to access columns displayed in a specific band via the GridBand.Columns collection). A column collection provides indexed access to columns. The indexer can accept two types of parameters: a column's bound field name or its index within the collection. In the first case, the parameter value is compared to a column's GridColumn.FieldName property.

The following code line shows how to move focus to a column bound to the 'UnitPrice' field.

The column collection provides additional methods for accessing columns. The GridColumnCollection.ColumnByName method gets a column with a specified name. This method can be used when the column name is stored in a variable. Otherwise, you can access a column by its name directly, as described above. You can also use the GridColumnCollection.ColumnByFieldName method to obtain a column specified by its bound field name. This is an alternative to using an index notation.

Expanded Identifying Columns

This section assumes that you retrieve a column object as the return value of a property, method or an event parameter. Often, you will need to identify the column retrieved. The GridColumn (as well as the inherited BandedGridColumn) class provides a number of properties that can be used for this purpose. The table below lists the ones you will use most often.

Property Description
GridColumn.Name Available only for columns created at design time. This value is unique, since components on the same form cannot have identical names.
GridColumn.FieldName Specifies the bound data field name. This value is not necessarily unique since Views allow you to create multiple columns bound to the same data field. On the other hand, you will rarely, if ever, need to create more than one column displaying the same field values.
GridColumn.AbsoluteIndex Specifies the column position within the owning collection. This value is unique for columns owned by the View.
GridColumn.ColumnHandle Specifies the bound data field's index within an associated data source. Like the GridColumn.FieldName property, this value is not necessarily unique, since Views allow you to create multiple columns bound to a single data field.

Expanded See Also

How would you rate this topic?​​​​​​​