$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
Data Grid WinForms Control
Create data gird view in C# with modern user interface for your Windows Forms applications
Home > WinForms UI Controls > User Manual > Access Columns and Iterate through Columns in C#

C# Grid Column Accessing and Iterating

While using Data Grid control to design columns, we need to access and iterate through columns. We can access a column by name or index and iterate through grid columns with the Columns collection of Data Grid Column objects. To access and iterate the grid columns to Data Grid Control in C# projects, we can use the C# code snippet below.

Access Columns in C#

To access columns in grid, we can use the name or index of columns. Actually, the name is preferred access of columns, as it allows users of the Data Grid control reorder the columns and change the index of the columns simultaneously. The following C# code snippet shows how to configure the width of an image column.

((GridImageColumn)this.ketticGrid.Columns["Photo"]).Width = 100;

Iterate Columns in C#

To iterate through grid columns, we can use the Columns collection of Data Grid Column objects. The following sample will cycle through columns of the grid column, and then control whether the column is a data grid column type, finally set the header text of each column to the number of column.

int i = 0;
foreach (GridColumn column in ketticGrid.Columns)
if (column is GridDataColumn)
GridDataColumn col = column as GridDataColumn;
if (col != null)
col.Width = 120;
col.HeaderText = "Column count : " + i.ToString();

Iterate via Hierarchical Columns in C#

It is able to iterate via hierarchical Data Grid with iterate via the column collection of Data Grid control template. The following C# code snippet shows how to achieve this.
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls