Hi!
I have to use custom cell to display data but I have problem with performance.
I have 500 rows and when I use my custom cell scrolling is very slow, not fluent.
I made simple test and checked that even if I add only one child control to custom cell, scrolling performance goes down significantly.
Is there any way to improve performance in this kind of scenario?
This is my source code:
public
class
CustomCell : GridDataCellElement
{
private
RadCheckBoxElement _chk;
public
CustomCell(GridViewColumn column, GridRowElement row) :
base
(column, row)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
_chk =
new
RadCheckBoxElement();
_chk.Margin =
new
Padding(2, 2, 2, 2);
_chk.MinSize =
new
Size(20, 20);
_chk.Text =
string
.Empty;
_chk.ToggleState = ToggleState.Off;
this
.Children.Add(_chk);
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridDataCellElement); } }
}
namespace
PerformanceIssue
{
public
partial
class
Form1 : Form
{
List<MySample> _list;
public
Form1()
{
InitializeComponent();
_list =
this
.GenerateList();
}
private
void
btnPopulateUnbound_Click(
object
sender, EventArgs e)
{
GridViewDataColumn col =
null
;
GridViewRowInfo row =
null
;
for
(
int
index = 1; index <= 10; index++)
{
col =
new
CustomColumn();
radGridViewUnbound.Columns.Add(col);
col.Width = 100;
}
foreach
(MySample item
in
_list)
{
row = radGridViewUnbound.Rows.AddNew();
row.Cells[0].Value = item.Property1;
row.Cells[1].Value = item.Property2;
row.Cells[2].Value = item.Property3;
row.Cells[3].Value = item.Property4;
row.Cells[4].Value = item.Property5;
row.Cells[5].Value = item.Property6;
row.Cells[6].Value = item.Property7;
row.Cells[7].Value = item.Property8;
row.Cells[8].Value = item.Property9;
row.Cells[9].Value = item.Property10;
}
radGridViewUnbound.MultiSelect =
true
;
}
private
List<MySample> GenerateList()
{
List<MySample> list =
new
List<MySample>();
MySample item =
null
;
for
(
int
index = 0; index < 500; index++)
{
item =
new
MySample()
{
Property1 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 1),
Property2 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 2),
Property3 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 3),
Property4 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 4),
Property5 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 5),
Property6 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 6),
Property7 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 7),
Property8 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 8),
Property9 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 9),
Property10 =
string
.Format(
"Row: {0}, Col: {1}"
, index, 10)
};
list.Add(item);
}
return
list;
}
}
}
Regards
Private
Sub
RadButton1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
RadButton1.Click
Try
Me
.Cursor = Cursors.WaitCursor
For
Each
row
As
GridViewRowInfo
In
Me
.RadGridView1.SelectedRows
row.IsVisible =
False
Next
Finally
Me
.Cursor = Cursors.
Default
End
Try
End
Sub
Private
Sub
RadButton1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
RadButton1.Click
Try
Me
.Cursor = Cursors.WaitCursor
Me
.RadGridView1.BeginUpdate()
For
Each
row
As
GridViewRowInfo
In
Me
.RadGridView1.SelectedRows
row.IsVisible =
False
Next
Me
.RadGridView1.EndUpdate(
True
)
Finally
Me
.Cursor = Cursors.
Default
End
Try
End
Sub
Hello!
I have an issue with assigning the ImageIndex of GridCellElement.
Let’s take a simple code sample. An image list with a single image is assigned to the grid view. All settings are by default.
01.
public
partial
class
Form1 : Form
02.
{
03.
public
Form1()
04.
{
05.
InitializeComponent();
06.
07.
for
(
int
i = 0; i < 8; i++)
08.
radGridView1.Columns.Add(
new
GridViewTextBoxColumn());
09.
10.
for
(
int
i = 0; i < 8; i++)
11.
radGridView1.Rows.Add(radGridView1.Rows.NewRow());
12.
}
13.
14.
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
15.
{
16.
if
((e.CellElement.RowIndex + e.CellElement.ColumnIndex) % 2 == 0)
17.
{
18.
e.CellElement.ImageIndex = 0;
19.
}
20.
}
21.
}
When I build this sample with “RadControls for WinForms Q3 2009 SP1” it shows the “chessboard”. But when I build it with the latest “RadControls for WinForms Q2 2010 SP2” it shows an empty grid.
To have it running as expected I have to do the following workaround (see line 5):
1.
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
2.
{
3.
if
((e.CellElement.RowIndex + e.CellElement.ColumnIndex) % 2 == 0)
4.
{
5.
e.CellElement.ImageIndex = -1;
6.
e.CellElement.ImageIndex = 0;
7.
}
8.
}
So, perhaps this is a bug.
Thank
you.