G
Gert
Hi
I have two classes, Trade and TradeAssets. I create a form with a
PropertyGrid and set the trade object to the SelectedObject object of
the PropertyGrid.
As I understand the collection editor picks up the type of the Item
property of the collection to determine what objects to create when
the add button is pressed.
:
:
oTrade = new Trade();
propertyGrid1.SelectedObject = oTrade;
:
:
[Serializable()]
public class Trade
{
private double _Quantity;
private double _Price;
private double _Value;
private ArrayList _TradeAssetsList;
//private TradeAssets[] _TradeAssetsList;
[Description("Number of shares"),Category("General")]
public double Quantity
{
get { return _Quantity; }
set { _Quantity = value;}
}
[Description("The price of the share"),Category("General")]
public double Price
{
get { return _Price; }
set { _Price = value;}
}
[Description("Value of the shares"),Category("General")]
public double Value
{
get { return _Value; }
set { _Value = value;}
}
[XmlArrayItem(ElementName= "TradeAssets", Type =
typeof(TradeAssets))]
public ArrayList TradeAssetsList
{
get { return _TradeAssetsList; }
set { _TradeAssetsList = value;}
}
// [XmlArrayItem(ElementName= "TradeAssets", Type =
typeof(TradeAssets))]
// public CTradeAssets[] TradeAssetsList
// {
// get { return _TradeAssetsList; }
// set { _TradeAssetsList = value;}
// }
public Trade()
{
TradeAssetsList = new ArrayList();
//TradeAssetsList.Add(new TradeAssets());
}
}
[Serializable()]
public class TradeAssets
{
private double _Quantity;
[Description("Number of shares"),Category("General")]
public double Quantity
{
get { return _Quantity; }
set { _Quantity = value;}
}
public TradeAssets()
{
}
}
Q: If I declare 'private TradeAssets[] _TradeAssetsList;' the
collection editor works fine. If I declare 'private ArrayList
_TradeAssetsList;' is creates System.Objects when I press the add
button. I would have thought that if I say the typeof the ArrayList is
of type TradeAssets, '[XmlArrayItem(ElementName= "TradeAssets", Type =
typeof(TradeAssets))]', the collection editor would pick it up?
I wouldn't like to write a collection class for every object or is
this the only way
public sealed class TradeAssetsCollection : CollectionBase
{
public TradeAssets this[int index]
{
get
{
return(TradeAssets)(List[index]);
}
set
{
List[index] = value;
}
}
}
Thanks
Gert
I have two classes, Trade and TradeAssets. I create a form with a
PropertyGrid and set the trade object to the SelectedObject object of
the PropertyGrid.
As I understand the collection editor picks up the type of the Item
property of the collection to determine what objects to create when
the add button is pressed.
:
:
oTrade = new Trade();
propertyGrid1.SelectedObject = oTrade;
:
:
[Serializable()]
public class Trade
{
private double _Quantity;
private double _Price;
private double _Value;
private ArrayList _TradeAssetsList;
//private TradeAssets[] _TradeAssetsList;
[Description("Number of shares"),Category("General")]
public double Quantity
{
get { return _Quantity; }
set { _Quantity = value;}
}
[Description("The price of the share"),Category("General")]
public double Price
{
get { return _Price; }
set { _Price = value;}
}
[Description("Value of the shares"),Category("General")]
public double Value
{
get { return _Value; }
set { _Value = value;}
}
[XmlArrayItem(ElementName= "TradeAssets", Type =
typeof(TradeAssets))]
public ArrayList TradeAssetsList
{
get { return _TradeAssetsList; }
set { _TradeAssetsList = value;}
}
// [XmlArrayItem(ElementName= "TradeAssets", Type =
typeof(TradeAssets))]
// public CTradeAssets[] TradeAssetsList
// {
// get { return _TradeAssetsList; }
// set { _TradeAssetsList = value;}
// }
public Trade()
{
TradeAssetsList = new ArrayList();
//TradeAssetsList.Add(new TradeAssets());
}
}
[Serializable()]
public class TradeAssets
{
private double _Quantity;
[Description("Number of shares"),Category("General")]
public double Quantity
{
get { return _Quantity; }
set { _Quantity = value;}
}
public TradeAssets()
{
}
}
Q: If I declare 'private TradeAssets[] _TradeAssetsList;' the
collection editor works fine. If I declare 'private ArrayList
_TradeAssetsList;' is creates System.Objects when I press the add
button. I would have thought that if I say the typeof the ArrayList is
of type TradeAssets, '[XmlArrayItem(ElementName= "TradeAssets", Type =
typeof(TradeAssets))]', the collection editor would pick it up?
I wouldn't like to write a collection class for every object or is
this the only way
public sealed class TradeAssetsCollection : CollectionBase
{
public TradeAssets this[int index]
{
get
{
return(TradeAssets)(List[index]);
}
set
{
List[index] = value;
}
}
}
Thanks
Gert