我是在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