MultiRow Windows Forms > Developer's Guide > Using MultiRow > Grid > Tips on Improving the Performance |
This section introduces code examples to improve the speed and memory usage.
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.
The following code suppresses the rendering of the control.
' Suppress the rendering of the control. GcMultiRow1.SuspendLayout() ' TODO: Changes on GcMultiRow control ' Resume the rendering of the control GcMultiRow1.ResumeLayout() |
// Suppress the rendering of the control gcMultiRow1.SuspendLayout(); // TODO: Changes on GcMultiRow control // Resume the rendering of the control gcMultiRow1.ResumeLayout(); |
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.
The GcMultiRow.GetValue method and the GcMultiRow.SetValue method provide an even more efficient way to access cell values than the Cell.Value property.
The following code indexes the row and cell.
GcMultiRow1.Rows(0).Cells(1).Value = 1234 |
gcMultiRow1.Rows[0].Cells[1].Value = 1234; |
The following code provides direct access to the values inside the control.
GcMultiRow1.SetValue(0, 1, 1234) |
gcMultiRow1.SetValue(0, 1, 1234); |
The following can also be used for the same functionality.
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.
The following code sets the value of all the cells to null (Nothing in Visual Basic), except for the header cells.
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 |
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); } } |
When you are handling large amounts of data, it is more efficient to use bound mode instead of unbound mode.
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.
The following example illustrates using the DefaultCellStyle property.
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 |
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; |