How to use GridView with VirtualQueryableCollectionView for growing datasource?

7 posts, 0 answers
  1. rick
    rick avatar
    6 posts
    Member since:
    Jan 2016

    Posted 11 Sep Link to this post

    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!

     

     

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 12 Sep Link to this post

    Hello Rick,

    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
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. rick
    rick avatar
    6 posts
    Member since:
    Jan 2016

    Posted 12 Sep in reply to Stefan Nenchev Link to this post

    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? 

  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 14 Sep Link to this post

    Hello Rick,

    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
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. rick
    rick avatar
    2 posts
    Member since:
    Aug 2015

    Posted 18 Sep in reply to Stefan Nenchev Link to this post

    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;
            }
        }

     

     

  7. rick
    rick avatar
    2 posts
    Member since:
    Aug 2015

    Posted 18 Sep in reply to rick Link to this post

    I'm using UI for WPF Q3 2015\Binaries\WPF40\Telerik.Windows.Controls.GridView.dll
  8. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 21 Sep Link to this post

    Hello Rick,

    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
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready