Skip to content

Commit 7f07b53

Browse files
ES-1025386 Resolved the ReadMe Length Issues in Public Syncfusion Code Examples
1 parent 3119ca4 commit 7f07b53

1 file changed

Lines changed: 113 additions & 1 deletion

File tree

README.md

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
# WinForms-GridControl-Getting-Started
1+
# WinForms GridControl Getting Started
2+
This section will explain about creating simple Windows Forms GridControl and the overview of its basic functionalities.
3+
4+
## Adding GridControl through Code
5+
6+
Windows Forms GridControl can be added through code-behind by following the below steps.
7+
8+
1. Create a new Windows Form Application.
9+
2. Add the below assemblies into the project file
10+
- Syncfusion.Grid.Windows.dll
11+
- Syncfusion.Grid.Base.dll
12+
- Syncfusion.Shared.Base.dll
13+
- Syncfusion.Shared.Windows.dll
14+
15+
Initialize a GridControl by using the below code in code behind.
16+
17+
```csharp
18+
//Initializing a new Grid.
19+
private Syncfusion.Windows.Forms.Grid.GridControl gridControl1 = new Syncfusion.Windows.Forms.Grid.GridControl();
20+
```
21+
22+
Use the below code for adding the initialized GridControl to the application.
23+
24+
```csharp
25+
//Add required size for the Grid.
26+
this.gridControl1.Size = new System.Drawing.Size(344, 250);
27+
this.Controls.Add(this.gridControl1);
28+
```
29+
30+
## Populating Data
31+
32+
Windows Forms GridControl is a cell based control and hence to populate the GridControl, RowCount and ColCount are necessary. By default the RowCount and ColCount values are 10. Data can be populated by any one of the following methods.
33+
34+
Populate data by looping through cells in GridControl.
35+
36+
```csharp
37+
//Specifying row and column count
38+
gridControl1.RowCount = 15;
39+
gridControl1.ColCount = 4;
40+
41+
//Looping through the cells and assigning the values based on row and column index
42+
for (int row = 1; row <= gridControl1.RowCount; row++)
43+
{
44+
for (int col = 1; col <= gridControl1.ColCount; col++)
45+
{
46+
gridControl1.Model[row, col].CellValue = string.Format("{0}/{1}", row, col);
47+
}
48+
}
49+
```
50+
51+
## Cell Styles
52+
53+
In Windows Forms GridControl, each cell contains distinct style information and can be customized independently using GridStyleInfo objects.
54+
55+
### Modifying Cell Styles through Designer
56+
57+
To edit cell styles in Designer mode, select the grid and click Edit to access the designer surface. Use the PropertyGrid to modify appearance and style settings for the whole grid or selected range of cells.
58+
59+
### Modifying Cell Styles through Code
60+
61+
Use GridStyleInfo class to customize cell appearance and apply the style to desired range of cells.
62+
63+
```csharp
64+
//Creates GridStyleInfo object.
65+
GridStyleInfo style = new GridStyleInfo();
66+
67+
//Set properties to it.
68+
style.BackColor = Color.DarkGreen;
69+
style.TextColor = Color.White;
70+
style.Font.Facename = "Verdana";
71+
style.Font.Bold = true;
72+
style.Font.Size = 9f;
73+
74+
//Apply the style to desired range of cells.
75+
this.gridControl1.ChangeCells(GridRangeInfo.Cells(2, 2, 4, 2), style);
76+
```
77+
78+
## Selection
79+
80+
Windows Forms GridControl provides two types of selection: Range selection (cell-based) and Record selection (record-based).
81+
82+
For record selection, set the ListBoxSelectionMode property:
83+
84+
```csharp
85+
this.gridControl1.ListBoxSelectionMode = SelectionMode.None;
86+
```
87+
88+
For range selection, set the AllowSelection property:
89+
90+
```csharp
91+
this.gridControl1.AllowSelection = Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Any;
92+
```
93+
94+
Selection operations can be handled using SelectionChanging and SelectionChanged events.
95+
96+
## Editing
97+
98+
By default the GridControl is in editable state. Use the ReadOnly property to enable or disable editing for the whole grid or individual cells.
99+
100+
```csharp
101+
// Disabling Edit mode for the whole Grid.
102+
this.gridControl1.ReadOnly = false;
103+
104+
// Disabling edit mode for a particular cell.
105+
GridStyleInfo style = gridControl1.Model[2, 2];
106+
style.ReadOnly = false;
107+
```
108+
109+
Editing operations can be customized using CurrentCellStartEditing and CurrentCellEditingComplete events.
110+
111+
## For More Information
112+
113+
Refer to the Syncfusion WinForms GridControl documentation: [Getting Started Guide](https://help.syncfusion.com/windowsforms/grid-control/getting-started)

0 commit comments

Comments
 (0)