Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1015
Bindable Dynamc Data Structure
posted

I have a data structure that is an TestDataCollection<TestData> which derives from List<TestData> and implements ITypedList. My TestData object derives from List<T> and has some additional helper properties. Each TestData objects represents a column of data that I want to display in the XamDataGrid. When the TestDataCollection is bound to a xamDataGrid, if I have one item in the collection, the correct data shows, but the column header is wrong (just says Value). But if I have more that one, the correct names show in the Column Headers, but the data is not being displayed.

Our current solution used the ADO.Net DataTable, which binds great for small amounts of data, but I need to scale to 20-30 columns and 10,000,000 rows. I am open to changing this data structure to facilitate fast updatable binding. But I have other objects that also must use this as a bindable source.

Thanks for any help and insight.

public class TestData : List<double> 
    {
        private string header;         
        private int series = 0;
        private int sheet = 0;
                
        public TestData() : base()
        {
 
        }
 
        public string Header
        {
            get
            {
                return header;
            }
 
            set
            {
                header = value;                               
            }
        }                                                                                                                                                              
 
        public int Series
        {
            get
            {
                return series;
            }
 
            set
            {
                series = value;
            }
        }
 
        public int Sheet
        {
            get
            {
                return sheet;
            }
 
            set
            {
                sheet = value;
            }
        }                 
 
        
    }

public class TestDataCollection  : List<TestData>, ITypedList
    {                                                                  
        private List<string> testDataLUT = new List<string>();           
 
        public TestDataCollection() : base()
        {
    
        }
 
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
 
            List<PropertyDescriptor> props = new List<PropertyDescriptor>();
            
            for (int x = 0; x < this.Count; x++)
            {                                                 
                props.Add(new TestDataPropertyDescriptor(this[x].Header));               
            }
 
            return new PropertyDescriptorCollection(props.ToArray<PropertyDescriptor>(), true);
            
        }
 
        public void AddTestData(TestData data)
        {
            if (testDataLUT.Contains(data.Header))
            {
                int index = testDataLUT.IndexOf(data.Header);
                this[index].AddRange(data);
            }
            else
            {
                this.Add(data);
            }
        }
 
        public TestData GetTestData(string header)
        {
            int index = testDataLUT.IndexOf(header);
            return this[index];
        }
            
        public string GetListName(PropertyDescriptor[] listAccessors)
        {
            return "TestDataCollection";
        }
 
 
    }

public class TestDataPropertyDescriptor : PropertyDescriptor
    {
        int index = 0;
        string header = "";
        
        
        public TestDataPropertyDescriptor(string header)
            : base(header, null)
        {
            this.header = header;
        }
 
        public TestDataPropertyDescriptor(string header, int index)
            : base(header, null)
        {
            this.header = header;
            this.index = index;
        }     
 
        public override bool CanResetValue(object component)
        {
            return false;                           
        }
 
        public override Type ComponentType
        {
            get { return typeof(double); }
        }
 
        public override object GetValue(object component)
        {
            TestData data = (TestData)component;
 
            if (data != null)
            {
                for (int x = 0; x < data.Count; x++)
                {
                    return data[x];
                }
            }
            else
            {
                return 0;
            }
            return 0;         
        }
 
        public override bool IsReadOnly
        {
            get { return true; }                                                                                                        
        }
 
        public override Type PropertyType
        {
            get { return typeof(double); }
        }
 
        public override void ResetValue(object component)
        {
            
        }
 
        public override void SetValue(object component, object value)
        {
           
        }
 
        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }  
 
        
    }