[Mono-winforms-list] DataSource Property for Windows.Forms.Li stControl

Brian Takita brian.takita@runbox.com
Thu, 21 Aug 2003 01:12:14 -0700


This is a multi-part message in MIME format.
--------------090500060703000705050205
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

I added the code for the DataSource property.
I have done some reverse engineering work on the ComboBox and have a 
good idea of how the DataSource works with it.

I don't know where to add it in ComboBox.cs however.
Can you give me an overview on how the control works?
For ListBox, do I add the fill code in OnCreateControl?

Brian

Dennis Hayes wrote:

> Sounds like you know what you are doing.
> Go for it.
> Many controls use this functionality.
> You might check (ask on the list) to see if there is anything in the 
> other classes that you can use.
> If not, you might want to do the implmentation for some of the other 
> classes as well.
>  
> Welcome aboard.
> When you have code to checkin, post to the list and send me a copy.
> If I have time to lookit over and check it in, I will. Otherwise 
> someone from the list can do it.
> Dennis
>
>
> */Brian Takita <brian.takita@runbox.com>/* wrote:
>
>     Dennis,
>
>     Thank you for the intro to develop for Mono.
>
>     I asked the microsoft.public.dotnet.framework.csharp newsgroup
>     about how
>     to implement it in the thread
>     "How come nobody responds to Implementing DataSource Request??".
>
>     The list of tasks I got are:
>
>     - DataSources should implement the IList interface.
>     - If a DataView is passed in, then use that.
>     - In the case of a DataTable, you should use the DefaultView
>     property of
>     that table to get the view.
>     - Once you have your source, you can iterate through the list of
>     items and
>     display them, using reflection to get the value of the property to
>     display.
>     If the item returned in the list implements the ICustomTypeDescriptor
>     interface, use that.
>
>     They seem reasonable to me. I would have to add support for a
>     DataSet as
>     the DataSource property and the DataMember property to point to the
>     correct DataTable.
>
>     I think this covers most of the functionality of the DataSource
>     property. Unfortunately, its a sizeable black box, so some reverse
>     engineering is probably needed.
>     What do you think?
>
>     Brian Takita
>
>     Dennis Hayes wrote:
>
>     >Great!
>     >If you have not done so already, install a tarball (the version
>     0.26 just
>     >released, or a nightly snapshot) these include binaries to kick start
>     >development. When you get that to compile, do an anonymous
>     checkout from cvs
>     >and get that to compile.
>     >After that, start adding you new code.
>     >Post changes to the email list and get them oked. Make sure
>     someone checks
>     >them in to cvs. After a few checkins, we can get you a real cvs
>     account.
>     >No one is working on ListControl right now.
>     >
>     >Do you have a plan on how to implement the DataSource function?
>     >Dennis
>     >
>     >
>     >-----Original Message-----
>     >From: Brian Takita [mailto:brian.takita@runbox.com]
>     >Sent: Friday, August 15, 2003 2:12 PM
>     >To: mono-winforms-list@lists.ximian.com
>     >Subject: [Mono-winforms-list] DataSource Property for
>     >Windows.Forms.ListControl
>     >
>     >Hello,
>     >
>     >I'm creating a custom control that uses the DataSource property.
>     >
>     >I'm interested in contributing it to the Mono project for the
>     >Windows.Forms.ListControl
>     >
>     >Where do I go from here?
>     >
>     >Thank You,
>     >Brian Takita
>     >
>     >_______________________________________________
>     >Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
>     >http://lists.ximian.com/mailman/listinfo/mono-winforms-list
>     >
>     >
>     >
>     >
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Yahoo! SiteBuilder 
> <http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com> - 
> Free, easy-to-use web site design software 



--------------090500060703000705050205
Content-Type: text/plain;
 name="ListControl.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ListControl.cs"

//
// System.Windows.Forms.ListControl.cs
//
// Author:
//   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
//	Dennis Hayes (dennish@raytek.com)
// (C) 2002/3 Ximian, Inc
//
using System;
using System.Drawing;
using System.Collections;
using System.Reflection;

namespace System.Windows.Forms {

	// <summary>
	//
	// </summary>

    public abstract class ListControl : Control {

		protected string DisplayMember_ = String.Empty;

		private object _dataSource;
		//ControlStyles controlStyles;
		//
		//  --- Public Properties
		//
		[MonoTODO]
		public object DataSource {
			get {
				return _dataSource;
			}
			set {
				if(_dataSource != value) {
					if((value is IList) || (value is IListSource)) {
						_dataSource = value;
						OnDataSourceChanged(new EventArgs());
					}
					else {
						throw new Exception("Complex DataBinding accepts as a data source either an IList or an IListSource");
					}
				}
			}
		}
		[MonoTODO]
		public string DisplayMember {
			get {
				return DisplayMember_;
			}
			set {
				if( DisplayMember_ != value) {
					DisplayMember_ = value;
					OnDisplayMemberChanged(new EventArgs());
				}
			}
		}
		
		internal string getDisplayMemberOfObj( object obj) {
			string objectString = String.Empty;
			Type t = obj.GetType();
			if( DisplayMember != String.Empty) {
				if( t != null) {
					PropertyInfo prop = t.GetProperty(DisplayMember);
					if( prop != null) {
						objectString = prop.GetValue(obj, null).ToString();
					}
				}
			}
			if( objectString == String.Empty) {
				objectString = obj.ToString();
			}
			return objectString;
		}
		
		internal class ListControlComparer : IComparer {
			private ListControl owner_ = null;
			public ListControlComparer(ListControl owner) {
				owner_ = owner;
			}

			public int Compare(object x, object y) {
				return owner_.getDisplayMemberOfObj(x).CompareTo(owner_.getDisplayMemberOfObj(y));
			}
		}
		

		[MonoTODO]
		public abstract int SelectedIndex {get;set;}

		[MonoTODO]
		public object SelectedValue {
			get {
				throw new NotImplementedException ();
			}
			set {
				//FIXME:
			}
		}
		[MonoTODO]
		public string ValueMember {
			get {
				throw new NotImplementedException ();
			}
			set {
				//FIXME:
			}
		}

		//
		//  --- Public Methods
		//

		[MonoTODO]
		public string GetItemText(object item)
		{
			throw new NotImplementedException ();
		}

		//
		//  --- Public Events
		//
		[MonoTODO]
		public event EventHandler DataSourceChanged;
		[MonoTODO]
		public event EventHandler DisplayMemberChanged;

		//
		// --- Protected Constructor
		//
		[MonoTODO]
		protected ListControl()
		{
			
		}

		//
		//  --- Protected Properties
		//
		[MonoTODO]
		protected CurrencyManager DataManager {
			get {
				throw new NotImplementedException ();
			}
		}

		//
		//  --- Protected Methods
		//
		[MonoTODO]
		protected override bool IsInputKey(Keys keyData)
		{
			//FIXME:
			return base.IsInputKey(keyData);
		}
		[MonoTODO]
		protected virtual void OnDataSourceChanged(EventArgs e) {
			//FIXME:
		}
		[MonoTODO]
		protected virtual void OnDisplayMemberChanged(EventArgs e) {
			//FIXME:
		}

		[MonoTODO]
		protected virtual void OnSelectedIndexChanged(EventArgs e) {
			//FIXME:
		}		
		
		[MonoTODO]
		protected virtual void OnSelectedValueChanged(EventArgs e){
			//FIXME:
		}

		public event EventHandler SelectedValueChanged;
		public event EventHandler ValueMemberChanged;
		
		[MonoTODO]
		protected override void OnBindingContextChanged(EventArgs e)
		{
			//FIXME:
			base.OnBindingContextChanged(e);
		}

		[MonoTODO]
		protected abstract void RefreshItem(int index);

	 }
}

--------------090500060703000705050205--