|
/*
* 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.Drawing;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
using MyXaml;
namespace MyXaml.DotNet1_1
{
/// <summary>
/// Manage the ObjectCollection data type.
/// </summary>
public class ObjectCollectionModel : PropertyModelBase
{
/// <summary>
/// Add a series of items to the parent's Items collection.
/// </summary>
/// <param name="obj">The object instance.</param>
/// <param name="pi">The PropertyInfo instance.</param>
/// <param name="val">Not used.</param>
/// <param name="target">Not used.</param>
/// <returns>null</returns>
public override object SetValue(object obj, PropertyInfo pi, object val)
{
try
{
foreach(XmlElement childElement in currentNode.ChildNodes)
{
// get the Item text
string text=childElement.InnerText;
// get the current items collection
object items=pi.GetValue(obj, null);
// there are different types of ObjectCollection containers
if (items.GetType()==typeof(ComboBox.ObjectCollection))
{
((ComboBox.ObjectCollection)items).Add(text);
}
else if (items.GetType()==typeof(ListBox.ObjectCollection))
{
((ListBox.ObjectCollection)items).Add(text);
}
else if (items.GetType()==typeof(CheckedListBox.ObjectCollection))
{
((CheckedListBox.ObjectCollection)items).Add(text);
}
}
}
catch(Exception e)
{
Trace.WriteLine("ObjectCollection: Setter failed for: "+pi.ToString()+" val="+val+" "+e.Message);
}
return null;
}
}
}
|
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