Utiliser une listBox1.DataSource dans une Class
Bonjour,
alors je chercher à affichée la class Voiture dans ma listbox mais j'ai un problème
ma Class :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public class Voiture
{
public static Form1 f1 = Application.OpenForms.OfType<Form1>().FirstOrDefault();
public int Nombre { get; set; }
public string Nom { get; set; }
public static void car()
{
List<Voiture> Random = new List<Voiture>();
new Voiture() { Nombre = 5, Nom = "Subaru" };
new Voiture() { Nombre = 2, Nom = "Fiat" };
f1.listBox1.DataSource = Voiture;
f1.listBox1.DisplayMember = "Nom";
f1.textBox1.DataBindings.Add("Text", new List<Voiture>(), "Nombre");
f1.textBox1.Text = "TEST";
}
} |
mais j'ai une erreur
'Voiture' est un type,qui n'est pas valide dans le contexte donné
comment je peux faire pour que la lisbox accède à DataSource = Voiture ?
par contre quand je mais
Code:
1 2
|
f1.textBox1.Text = "TEST"; |
ça fonctionne
DataSource dans une Class
Bonjour j'ai reussi à mettre dans la listbox
Code:
1 2 3
|
var Random = new List<Voiture>();
Random.Add(new Voiture() { Nombre = 5, Nom = "Subaru" }); |
mais je rencontre un autre soussis :)
alors j'affiche tous dans la listbox tous fonctionne
mais je veut ajouter une textbox qui filtre la listbox donc j'ai ajouter
Code:
1 2 3 4 5
|
f1.textBox2.TextChanged += (s, e) =>
{
f1.listBox1.DataSource = Random.Where(x => x.Nom.Contains(f1.textBox2.Text)).ToList();
}; |
ça recherche bien le texte saisis mais sa actualise pas le Nombre
comment je peux faire pour synchroniser le text selectionné dans la listBox1.DisplayMember avec le textBox1.DataBindings ? svp ;