10Tec iGrid for WinForms is a first-class VB.NET and C# grid control. The object model of the control and the .NET Framework platform it is built on are ideal for use from VB.NET or C# source code in Microsoft Visual Studio or another IDE supporting these programing languages:
Actually iGrid.NET is a 2-dimensional array of cells. To start using this grid control in VB.NET or C# code, as a rule you define the required columns and rows first. iGrid creates the corresponding cells automatically and you can fill in them with values similar to items in a 2-dimensional array. Below you will see a basic code demonstrating how to create a 3x10 cells grid and populate this grid control in VB.NET:
With iGrid1 .Cols.Count = 3 .Rows.Count = 10 .Cells(0, 0).Value = "Some text" .Cells(0, 1).Value = 123 End With
The equivalent code to create a similar grid control in C# is the following:
iGrid1.Cols.Count = 3; iGrid1.Rows.Count = 10; iGrid1.Cells[0, 0].Value = "Some text"; iGrid1.Cells[0, 1].Value = 123;
As you can see, you access any cell by its numeric column and row index using the array syntax of the corresponding language (VB.NET or C#). Every item of the
Cells array is an
iGCell object representing one cell in the grid control. This cell object has properties like
Value to set or read the value of a cell,
BackColor to specify or retrieve the background color of the cell and a lot of other properties defining the cell look and behavior.
An alternative way to create grid control columns is to define them one-by-one using the
Add() method of the column collection object property:
iGrid1.Cols.Add() iGrid1.Cols.Add("Column 2") iGrid1.Cols.Add("Column 3", 125)
This VB.NET code defines 3 columns in a grid control named iGrid1. The first column has all properties set to their default values, the header of the second column will display "Column 2", the title and width of the third column will be set to "Column 3" and 125 respectively. The above VB.NET code snippet demonstrates usage of overloaded versions of the same method, which is a native feature of both C# and VB.NET languages.
You can even use named arguments to make code more understandable or change the order of parameters. For example, the third column of our grid control could be defined in VB.NET this way:
iGrid1.Cols.Add(width:=125, text:="Caption #2")
The same grid control initialization statement in C#:
iGrid1.Cols.Add(width: 125, text: "Caption #2");
Similar objects of the 10Tec VB.NET/C# grid control (columns, rows, cells, etc.) are gathered into collections. These collections are designed according to the .NET Framework standards and provide you with traditional methods to work with collection items (
Clear() and the like), to access them by index or to enumerate them in a For-Each loop available in the VB.NET and C# programming languages. To demonstrate this, let's display row indices in the cells of the first column of a grid control in VB.NET:
For Each cell As iGCell In iGrid1.Cols(0).Cells cell.Value = cell.RowIndex Next
The same task implemented in C#:
foreach (iGCell cell in iGrid1.Cols.Cells) cell.Value = cell.RowIndex;
The next several pages in the Control Tour describe particular features of our VB.NET and C# grid control in detail.