Frage

Ich bin einige Probleme auftreten, während Valuemember Eigenschaft meiner ComboBox Einstellung.

Die Linie comboBox1.ValueMember = "Code"; bricht meinen Code.

Hier ist mein Code:

Form1.cs:

private void Form1_Load(object sender, EventArgs e) {  
    ...  
    ...      
    MAPList MAP = new MAPList();  
    comboBox1.DataSource = MAP.All;  
    comboBox1.ValueMember = "Code";  
    ...  
    ...  
}

MAPList.cs:

public class MAPList {  
    public readonly List<MAP> All;

    public MAPList() {
        All = new List<MAP>();

        var MapData = // Getting map data

        foreach(MAP m in MapData) {
            All.Add(new Map(m.Name, m.Code));
        }
    }
}

MAP.cs:

public class MAP {  
    public readonly string Name;  
    public readonly string Code;

    public RadioCode(string name, string code) {
        Name = name;
        Code = code;
    }

    public override string ToString() {
        return String.Format("{0}: {1}", Name, Code);
    }
}
War es hilfreich?

Lösung

Versuchen Umwandlung Code als Property anstelle eines Mitglieds und dann bindend es

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top