[Gtk-sharp-list] Data grid comparable to the data grid control in MS/VS
monodanmorg at yahoo.com
Wed Sep 3 10:15:02 EDT 2008
In order to data bind a DataTable to a Gtk.TreeView using a ListStore treee model without referencing System.Data, you would using the System.ComponentModel interfaces that DataTable implements.
Both the DataGrid in System.Web and System.Windows.Forms use the interfaces from Sysstem.ComponentModel for data binding purposes.
You can use ideas from the method DataBind() in DataGrid.cs in sqlsharpgtk:
It uses the GetResolvedDataSource that was borrowed from mono's System.Web implementation.
It shows you various interfaces it uses to load the DataTable, such as,
And some classes:
DataTable implements IListSource. The DataGrid looks for an IListSource, if found, calls GetList() on it to return an IList. For a DataTable, this IList is a DataView. IList.ContainsListCollection returns false.
Then GetItemProperties is called on the DataView to return a PropertyDescriptorCollection.
The concrete classes in this collection are:
DataColumnPropertyDescriptor - describes a DataColumn in a DataRowView
DataRelationPropertyDescriptor - describes a DataRelation
In order to get each row, you would get an IEnumerable from the DataView.
This IEnumerable is an enumerator of DataRowsViews.
>From each DataRowView, get the ICustomTypeDescriptor. From there, call GetProperties to get another PropertyDescriptorCollection. Each property descriptor describes a field. So, call GetValue.
System.Windows.Forms does things differently.
--- On Wed, 7/23/08, Mike Kestner <mkestner at gmail.com> wrote:
> From: Mike Kestner <mkestner at gmail.com>
> Subject: Re: [Gtk-sharp-list] Data grid comparable to the data grid control in MS/VS
> To: "Christian Hoff" <christian_hoff at gmx.net>
> Cc: gtk-sharp-list at lists.ximian.com
> Date: Wednesday, July 23, 2008, 9:12 AM
> On Tue, 2008-07-22 at 07:59 +0200, Christian Hoff wrote:
> > I have written a custom TreeModel to display
> DataTables. With this one
> > it should be easy to display a DataTable in a
> Gtk.TreeView or any other
> > widget you want. Maybe it's even compatible with
> the Medsphere widget.
> > However, I had to make use of GInterface
> implementation which is only
> > supported in Gtk# 2.12 (see
> > http://www.mono-project.com/ImplementingGInterfaces)
> > Mike, how about adding a custom tree model to display
> DataTables to
> > Gtk.DotNet? I think this could really be a useful
> feature since Gtk#
> > completly lacks support for DataTables. I would
> volunteer to start
> > working on it if you want.
> There have been several efforts toward a
> "data-bound" tree model over
> the years. The archives should have links to fairly recent
> efforts to
> provide databinding for the entire toolkit.
> I would be more interested in including such a data binding
> than a tree
> model specifically written for DataTable. Although I also
> think such a
> project could easily stand on its own, and might be easier
> to integrate
> into applications than a Gtk# 2.next dependency.
> Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
More information about the Gtk-sharp-list