我是在C#中的高技术,我想插入一个对象到CheckedListBox
, 所以这个插入的项目将有一个标题内的检查列表(我的对象包含一个我想在CheckedListBox中显示它的字符串字段)。 例如,这是我的课:插入一个名称到checkedlistbox插入的对象的困难
public class InfoLayer
{
private string LayerName;
private List<GeoInfo> GeoInfos;
public InfoLayer()
{
LayerName = "New Empty Layer";
GeoInfos = new List<GeoInfo>();
}
public InfoLayer(string LayerName)
{
this.LayerName = LayerName;
GeoInfos = new List<GeoInfo>();
}
public InfoLayer(string LayerName,List<GeoInfo> GeoInfosToClone):this(LayerName)
{
foreach (GeoInfo item in GeoInfosToClone)
{
GeoInfos.Add((GeoInfo)((ICloneable)item).Clone());
}
}
public GeoInfo SearchElement(long id)
{
foreach (GeoInfo info in GeoInfos) // foreach loop running on the list
{
if (info.INFOID == id)
return info; // return the item if we found it
}
return null;
}
public GeoInfo SearchElement(string name)
{
foreach (GeoInfo info in GeoInfos)
{
if (info.INFONAME.CompareTo(name)==0)
return info;
}
return null;
}
public override string ToString()
{
string toReturn = "";
for (int i = 0; i < GeoInfos.Count; i++) // for loop running on the list
{
toReturn += String.Format("{0}\n",GeoInfos[i].ToString()); // piping another geoinfo
}
return toReturn;
}
public string LAYERNAME{get{return LayerName;}}
我的类也包含在她里面一个toString置换器(不是我想要显示)
在此先感谢您的帮助。
,你能告诉我们你的尝试和一些类的代码? – 2010-11-22 19:14:54
您希望您的新行显示在CheckedListBox中? – 2010-11-22 19:56:41
该层的名字我可以创建一个道具吧...我的类包含一个字符串名称字段,我将道具添加到问题 – 2010-11-22 19:58:04