|
/*
* Copyright (c) 2004 Marc Clifton
* All Rights Reserved
*
* License: GNU General Public License, see doc\license.txt
* http://www.gnu.org/licenses/licenses.html#GPL
* Owner: Marc Clifton email: webmaster@knowledgeautomation.com
* First release published:
* http://www.codeproject.com/cs/miscctrl/xmlGuiGenerator.asp
* 2/25/04
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
namespace MyXaml.Extensions
{
[TypeConverter(typeof(DataSourceTypeConverter))]
public class DataSource
{
protected DataTable source;
protected string field;
protected string name;
public DataTable Source
{
get {return source;}
set {source=value;}
}
public string Field
{
get {return field;}
set {field=value;}
}
public string Name
{
get {return name;}
set {name=value;}
}
public DataSource()
{
}
public override string ToString()
{
if ( (source != null) && (field != null) )
{
return (string)source.Rows[0][field];
}
return "";
}
}
public class DataSourceTypeConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type t)
{
if (t.FullName=="System.Object") return true;
if (t.FullName=="System.Data.DataTable") return true;
return false;
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
object ret=null;
DataSource ds=(DataSource)value;
if (destinationType.FullName=="System.Object")
{
// return the DataTable when being assigned the a DataSource property.
ret=ds.Source;
}
else
if (destinationType.FullName=="System.Data.DataTable")
{
ret=ds.Source;
}
return ret;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here