When updating values of like 1000 cells every 500ms (for example), the UI would lock.
I also did this experiment with 100ms update rate, and the grid was not able to handle it.
The reason I'm checking it is because in my project, I'm connected to a remote hardware from which I read a byte array that represents the data of the cells.
I already wrote the mechanism that knows which rows are visible and therefore reads only the byte array that corresponds the visible rows.
Updating values on none visible rows should almost have no affect because of the UI virtualization.
I know that there is a chance that some cells on the DataTable (my ItemsSource) will not have their value changed on the remote hardware (and in this case I can optimize my code, so it won't overwrite the value, to prevent notification to the UI), but in my example, I'm taking the worst case scenario....
I have decided to check it with some more data grids.
Syncfusion - Almost the same poor performances.
Component One FlexGird - Good performance but lots of bugs (values doesn't get updated after scroll etc).
Micorsoft DataGrid - Good performance
ListView with GridView - Very good performance.
Another thing, GroupRenderMode="Flat" should increase the scroll performance (at least from what your documentation says), but it actually makes it worse!
Is there a better way of doing what I do? (Is there a way of getting the performance at least near the ListView or the DataGrid?)
Thanks.
I'm unable to attach the solution, but here is the code:
I also did this experiment with 100ms update rate, and the grid was not able to handle it.
The reason I'm checking it is because in my project, I'm connected to a remote hardware from which I read a byte array that represents the data of the cells.
I already wrote the mechanism that knows which rows are visible and therefore reads only the byte array that corresponds the visible rows.
Updating values on none visible rows should almost have no affect because of the UI virtualization.
I know that there is a chance that some cells on the DataTable (my ItemsSource) will not have their value changed on the remote hardware (and in this case I can optimize my code, so it won't overwrite the value, to prevent notification to the UI), but in my example, I'm taking the worst case scenario....
I have decided to check it with some more data grids.
Syncfusion - Almost the same poor performances.
Component One FlexGird - Good performance but lots of bugs (values doesn't get updated after scroll etc).
Micorsoft DataGrid - Good performance
ListView with GridView - Very good performance.
Another thing, GroupRenderMode="Flat" should increase the scroll performance (at least from what your documentation says), but it actually makes it worse!
Is there a better way of doing what I do? (Is there a way of getting the performance at least near the ListView or the DataGrid?)
Thanks.
I'm unable to attach the solution, but here is the code:
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading.Tasks;
using System.Threading;
namespace WpfGridsPerformanceTest
{
public class MainViewModel : ViewModelBase
{
private MyDT _data;
private DelegateCommand _changeValuesCommand;
public MainViewModel()
{
_data = new MyDT();
for (int i = 0; i <
400
; i++)
{
DataRow
row
=
_data
.NewRow();
_data.Rows.Add(row);
}
}
public DataView Items
{
get
{
return _data.DefaultView;
}
}
public DelegateCommand ChangeValuesCommand
{
get
{
if (_changeValuesCommand == null)
{
_changeValuesCommand
=
new
DelegateCommand(changeValues);
}
return _changeValuesCommand;
}
}
private void changeValues()
{
Task
t
=
new
Task(() =>
{
while (true)
{
foreach (DataRow row in _data.Rows)
{
for (int i = 0; i <
row.ItemArray.Count
(); i++)
{
row[i] = (int)row[i] + 1;
}
}
Thread.Sleep(500);
}
});
t.Start();
}
}
}
<Window
x:Class
=
"WpfGridsPerformanceTest.MainWindow"
xmlns:local
=
"clr-namespace:WpfGridsPerformanceTest"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
WindowState
=
"Maximized"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
local:Telerik
/>
<!--<local:Syncfusion />-->
<!--<local:DataGrid />-->
<!--<local:ListView />-->
<
Button
Grid.Row
=
"1"
FontWeight
=
"Bold"
FontSize
=
"16"
Command
=
"{Binding ChangeValuesCommand}"
>Click to start changing values</
Button
>
</
Grid
>
</
Window
>
<
UserControl
x:Class
=
"WpfGridsPerformanceTest.Telerik"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"300"
>
<
Grid
>
<
telerik:RadGridView
ItemsSource
=
"{Binding Items}"
ShowGroupPanel
=
"False"
UseLayoutRounding
=
"False"
RowIndicatorVisibility
=
"Collapsed"
DataLoadMode
=
"Synchronous"
CanUserFreezeColumns
=
"False"
CanUserSortColumns
=
"False"
CanUserSelect
=
"True"
SelectionMode
=
"Single"
SelectionUnit
=
"FullRow"
/>
</
Grid
>
</
UserControl
>