This is a migrated thread and some comments may be shown as answers.

Data virtualization empty grid

1 Answer 33 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Omer Javed
Top achievements
Rank 1
Omer Javed asked on 26 Jul 2013, 11:11 AM
Hello,

I am using VirtualQueryableCollectionView to implement Data Virtualization. Upon receiving data in completed event of a service call i am calling the Load method of the view. However it doesn't populate the view with received items and the grid remains empty. Here is the piece of code which tries to load items into view.

public void OnLookupCompleted(object sender, LookupRecordsCompletedEventArgs e)
        {
...
DynamicItems.Load(0, PrepareDynamicRows(e.Response.LookupRows));
 ...
}
 
public ObservableCollection<dynamic> PrepareDynamicRows(List<LookupRow> lookupRows)
        {
            ObservableCollection<dynamic> dynamicRows = new ObservableCollection<dynamic>();
            lookupRows.ForEach(x => dynamicRows.Add(new DynamicRow(x)));
            return dynamicRows;
        }

Here is the implementation of DynamicRow class which might help.

public class DynamicRow : DynamicObject, INotifyPropertyChanged
    {
        LookupRow _lookupRow;
 
        public DynamicRow()
        {
            _lookupRow = new LookupRow();
        }
 
        public DynamicRow(LookupRow lookupRow)
        {
            _lookupRow = lookupRow;
        }
 
        public override IEnumerable<string> GetDynamicMemberNames()
        {
            // output the avaiable names based on the dictionary of colum data, plus the Id field
            List<string> names = new List<string>();
            names.Add("Id");
            names.AddRange(_lookupRow.ColumnData.Keys);
 
            return names;
        }
 
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = this[binder.Name];
            return true;
        }
 
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            this[binder.Name] = value;
            return true;
        }
 
        /// <summary>
        /// Provides an indexer to retrieve either the Id or a value from the dictionary
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        public object this[string columnName]
        {
            get
            {
                if (columnName == "Id")
                {
                    return _lookupRow.RelatedEntity.Id;
                }
 
                if (_lookupRow.ColumnData.ContainsKey(columnName))
                {
                    return _lookupRow.ColumnData[columnName];
                }
 
                return null;
            }
            set
            {
                if (columnName == "Id")
                {
                    _lookupRow.RelatedEntity.Id = value as string;
                    return;
                }
 
                if (!_lookupRow.ColumnData.ContainsKey(columnName))
                {
                    _lookupRow.ColumnData.Add(columnName, value);
 
                    OnPropertyChanged(columnName);
                }
                else
                {
                    if (_lookupRow.ColumnData[columnName] != value)
                    {
                        _lookupRow.ColumnData[columnName] = value;
 
                        OnPropertyChanged(columnName);
                    }
                }
            }
        }
 
        public LookupRow LookupRow
        {
            get { return _lookupRow; }
            set { _lookupRow = value; }
        }
 
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
 
        #region INotifyPropertyChanged Members
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        #endregion
    }

Please can you guide what may be missing to successfully load items into view. Thanks.


Regards,
Omer Javed

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 31 Jul 2013, 11:23 AM
Hi,

I would suggest you to check our online documentation for more information on using Data Virtualization. Moreover, you can check our online demo here.

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Omer Javed
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or