GrapeCity MultiRow Windows Forms Documentation
Tips on Improving the Performance

This section introduces code examples to improve the speed and memory usage.

Suppress the Rendering of the Control

You can improve the performance by first suppressing the rendering before making any changes, and then by resuming the rendering after the changes are done. Use the following methods to suppress and resume the rendering.

These methods are the same as for the System.Windows.Forms.ListBox or System.Windows.Forms.DataGridView.

Using Code

The following code suppresses the rendering of the control.

[VB]

' Suppress the rendering of the control. 
GcMultiRow1.SuspendLayout()

' TODO: Changes on GcMultiRow control

' Resume the rendering of the control
GcMultiRow1.ResumeLayout()

[CS]

// Suppress the rendering of the control
gcMultiRow1.SuspendLayout();

// TODO: Changes on GcMultiRow control

// Resume the rendering of the control
gcMultiRow1.ResumeLayout();

Initialization

To improve the performance, the control is placed without a default template. If a default template is required, you can select "Default Template" from the smart tag.

Access to the Cell Values

The GcMultiRow.GetValue method and the GcMultiRow.SetValue method provide an even more efficient way to access cell values than the Cell.Value property.

Using Code

The following code indexes the row and cell.

[VB]

GcMultiRow1.Rows(0).Cells(1).Value = 1234

[CS]

gcMultiRow1.Rows[0].Cells[1].Value = 1234;

Using Code

The following code provides direct access to the values inside the control.

[VB]

GcMultiRow1.SetValue(0, 1, 1234)

[CS]

gcMultiRow1.SetValue(0, 1, 1234);

The following can also be used for the same functionality.

Access to Rows

Use the template information instead of accessing information for each row when retrieving similar types of row information (number of cells, cell types, and so on). This will make the processing faster.

Using Code

The following code sets the value of all the cells to null (Nothing in Visual Basic), except for the header cells.

[VB]

Imports GrapeCity.Win.MultiRow

' When accessing different rows individually
Dim gcMultiRow As GcMultiRow = Me.GcMultiRow1
For rowIndex As Integer = 0 To gcMultiRow.RowCount - 1
    For cellIndex As Integer = 0 To gcMultiRow.Rows(rowIndex).Cells.Count - 1
        If Not TypeOf gcMultiRow(rowIndex, cellIndex) Is HeaderCell Then
             gcMultiRow.SetValue(rowIndex, cellIndex, Nothing)
        End If
     Next
Next

' When accessing the template rows
Dim gcMultiRow As GcMultiRow = Me.GcMultiRow1
For rowIndex As Integer = 0 To gcMultiRow.RowCount - 1
    For cellIndex As Integer = 0 To gcMultiRow.Template.Row.Cells.Count - 1
        If Not TypeOf gcMultiRow.Template.Row.Cells(cellIndex) Is HeaderCell Then
            gcMultiRow.SetValue(rowIndex, cellIndex, Nothing)
         End If
    Next
Next

[CS]

using GrapeCity.Win.MultiRow;

// When accessing different rows individually
GcMultiRow gcMultiRow = this.gcMultiRow1;
for (int rowIndex = 0; rowIndex < gcMultiRow.RowCount; rowIndex++)
{
    for (int cellIndex = 0; cellIndex < gcMultiRow.Rows[rowIndex].Cells.Count; cellIndex++)
     {
        if (!(gcMultiRow[rowIndex, cellIndex] is HeaderCell))
             gcMultiRow.SetValue(rowIndex, cellIndex, null);
    }
}

// When accessing the template rows
GcMultiRow gcMultiRow = this.gcMultiRow1;
gcMultiRow.SuspendLayout();
for (int rowIndex = 0; rowIndex < gcMultiRow.RowCount; rowIndex++)
{
    for (int cellIndex = 0; cellIndex < gcMultiRow.Template.Row.Cells.Count; cellIndex++)
    {
        if (!(gcMultiRow.Template.Row[cellIndex] is HeaderCell))
             gcMultiRow.SetValue(rowIndex, cellIndex, null);
    }
}

Selection of Data Source

When you are handling large amounts of data, it is more efficient to use bound mode instead of unbound mode.

Cell Styles

The GcMultiRow.DefaultCellStyle property is more efficient than the GcMultiRow.Rows[0].Cells[0].Style property when you have to apply the same style to all the cells.

Using Code

The following example illustrates using the DefaultCellStyle property.

[VB]

Imports GrapeCity.Win.MultiRow

' Change the back color of all the cells(1)
Dim gcMultiRow As GcMultiRow = Me.GcMultiRow1
For rowIndex As Integer = 0 To gcMultiRow.RowCount - 1
    For cellIndex As Integer = 0 To gcMultiRow.Rows(rowIndex).Cells.Count - 1
         gcMultiRow(rowIndex, cellIndex).Style.BackColor = Color.Azure
    Next
Next

' Change the back color of all the cells(2)
Me.gcMultiRow1.DefaultCellStyle.BackColor = Color.Azure

[CS]

using GrapeCity.Win.MultiRow;

// Change the back color of all the cells(1)
GcMultiRow gcMultiRow = this.gcMultiRow1;
for (int rowIndex = 0; rowIndex < gcMultiRow.RowCount; rowIndex++)
{
    for (int cellIndex = 0; cellIndex < gcMultiRow.Template.Row.Cells.Count; cellIndex++)
    {
         gcMultiRow[rowIndex, cellIndex].Style.BackColor = Color.Azure;
    }
}

// Change the back color of all the cells(2)
this.gcMultiRow1.DefaultCellStyle.BackColor = Color.Azure;
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options