Custom Control TreeWeb and DataBinding
-
I have written a modification to the TreeWeb custom control found here on The Code Project. I needed to be able to bind data to any TreeElement that I choose. I have been able to do this by making the TreeElements controls themselves and using a ControlDesigner to allow me to make DataSource Selections to the properties. The issue I am having is that I can set the DataSource initially, but once I build, or close my project and try to open the page that has a TreeWeb, the DataSource is no longer editable through the properties. Instead it will be greyed out displaying 'System.Data.DataSet' as the value in the field. The other issue I'm having is when I bind the control in Page_Load it sees a filled DataSource as empty unless I reset the DataSource just before binding. Any help would be appreciated. I intend to post the source when I'm completed to help The Code Project out. Thanks. Here's the designer code from my designer related to DataSource // resolve ambiguous reference public string DataMember { get { Check.Require(this.mElement.DataMember != null); return this.mElement.DataMember; } set { this.mElement.DataMember = value; this.OnDataSourceChanged(); } } public string DataSource { get { DataBinding binding = base.DataBindings["DataSource"]; if(binding != null) { return binding.Expression; } return string.Empty; } set { // check to see if it needs to remove dataSource if((value == null) || (value.Length == 0)) { base.DataBindings.Remove("DataSource"); } else { // sets a new dataSource DataBinding binding = base.DataBindings["DataSource"]; if(binding == null) { binding = new DataBinding("DataSource", typeof(IEnumerable), value); } else { binding.Expression = value; } base.DataBindings.Add(binding); } this.OnDataSourceChanged(); base.OnBindingsCollectionChanged("DataSource"); } } protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); PropertyDescriptor prop = (PropertyDescriptor)properties["DataSource"]; AttributeCollection runtimeAttributes; if(prop!=null) { runtimeAttributes = prop.Attributes; // make a copy of the original attributes but make room for one extra attribute ie the TypeConver