| Using the C1FlexGrid Control > Cell Ranges |
CellRange objects allow you to work on arbitrary groups of cells as a single unit. For example, the code below creates a CellRange object, clears the data in the range, and assigns it a custom style:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Dim rg As CellRange = _flex.GetCellRange(3, 3, 10, 10)
rg.Data = Nothing
rg.Style = _flex.Styles("MyRangeStyle")
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
CellRange rg = _flex.GetCellRange(3, 3, 10, 10); rg.Data = null; rg.Style = _flex.Styles["MyRangeStyle"]; |
|
The CellRange object has a StyleNew property that retrieves the range style, if one exists, or creates a new one, assigns it to the range, and returns it. This property is convenient in situations where you don't need full-fledged control over formatting. For example, if all you want to do is give the range a red background, you can write:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Dim rg As CellRange = _flex.GetCellRange(3, 3, 10, 10) rg.StyleNew.BackColor = Color.Red |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
CellRange rg = _flex.GetCellRange(3, 3, 10, 10); rg.StyleNew.BackColor = Color.Red; |
|