Je suis abit nouveau en C# et j'essaye d'insérer un objet à CheckedListBox
, ainsi cet article inséré aura un titre dans la liste vérifiée (mon objet contient un champ de chaîne à l'intérieur que je veux être affiché dans CheckedListBox). par exemple ceci est ma classe:difficulté insérer un nom à un objet inséré d'une liste de contrôle
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;}}
ma classe contient également une overrider ToString en elle (pas ce que je veux afficher)
merci à l'avance pour votre aide.
pouvez-vous nous montrer un code de votre essai et de la classe? –
Comment aimeriez-vous que votre nouvelle ligne apparaisse dans votre CheckedListBox? –
le nom de la couche je peux créer un accessoire pour cela ... ma classe contient un champ de nom de chaîne je vais ajouter le prop à la question –