I'm trying to use RadGridView with VirtualQueryableCollectionView to display data from database.
The data is very large and it's growing in real time, let's say there are more than 25 rows will be added into database every second. And I want to refresh RadGridView to show real time data.
How can I do that? Is there any example?
Thanks very much!
6 Answers, 1 is accepted
We have a couple of demos on Data Virtualization in our WPF demos application, however, the source remains unchanged.
Please check the following forum thread where a similar topic was discussed - How to update items in a RadGridView with VirtualQueryableCollectionView as the scenario seems similar to yours.
Regards,
Stefan Nenchev
Telerik by Progress
Stefan, thanks for your quick reply.
I have checked the linked thread you mentioned. The first question in that thread is similar as mine. However, I don't find a final solution for it in that thread.
The solution Vlad given in that thread, use a timer to add a new item to VirtualQueryableCollectionView every second seems not applicable for my case, since the database is updated by other user via another application. And I don't know when and how many rows will be added. So I wonder if there is a way to simply "refresh" the underlying data source (the db query) every second manually, and gridview will automatically fetch the new data?
My colleague has suggested a possible approach in order to not reset the whole collection and respectively the RadGridView. However, you can invoke the Refresh method of the VirtualQueryableCollectionView which will recreate the view.
Regards,
Stefan Nenchev
Telerik by Progress
Thanks, Stefan! I have tried using the Refresh method, but I can't make it working. As shown in the screenshot, the gridview will not show the latest data in the SQLite database. You can see there are only 9 rows in the gridview which does not match the records number in SQLite database.
My code snippet:
public
partial
class
MainWindow : Window
{
private
const
string
_connStringTemplate =
"metadata=res://*/IomapMonitorModel.csdl|res://*/IomapMonitorModel.ssdl|res://*/IomapMonitorModel.msl;provider=System.Data.SQLite.EF6;provider connection string='data source={0}'"
;
private
const
string
_dbPath =
"t4.iop"
;
private
VirtualQueryableCollectionView _cv;
private
IomapMonitorEntities _context;
private
int
_tick = 0;
public
MainWindow()
{
InitializeComponent();
var _connStr = String.Format(_connStringTemplate, _dbPath);
_context =
new
IomapMonitorEntities(_connStr);
var query = _context.RawRecords.OrderBy(o => o.Id);
_cv =
new
VirtualQueryableCollectionView(query) { LoadSize = 100 };
DataContext = _cv;
StartRefresh();
}
private
void
StartRefresh()
{
var timer =
new
Timer(1000);
timer.Elapsed +=
new
ElapsedEventHandler((obj, e) =>
{
if
(_cv !=
null
)
{
if
(_tick < 20)
{
_context.RawRecords.Add(
new
RawRecord()
{
CardId = 0,
CardType =
"422"
,
ChannelId = 0,
Direction =
"RX"
,
ProtocolType =
"422"
,
Tick = _tick++,
TimeStamp = 11111,
Data =
new
byte
[] { 9, 8, 7 },
Miscellaneous =
null
});
_context.SaveChanges();
}
_cv.Refresh();
}
});
timer.AutoReset =
true
;
timer.Enabled =
true
;
}
}
Would it be possible to provide us with a sample project which we can review from our side and investigate in details so we can try to suggest a possible solution? As uploading projects in the forum thread is not possible, the best approach would be to create a ticket and we can proceed the discussion there.
Regards,
Stefan Nenchev
Telerik by Progress