Bonjour,

Je cherche depuis un bout de temps à apprendre à filtrer des données. Par exemple n'afficher que les synthés dont la notation est supérieur ou égale à 5 etc...
Tout ce que je cherche est hyper compliqué et je n'y comprend encorepas grand chose. Quelqu'un à une piste sérieuse ??

Voici mon code XAML :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
<Window x:Class="Raison2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <ListBox Name="lbSynth" ItemsSource="{Binding}" Margin="66,36,38,16" DisplayMemberPath="Nom" />
    </Grid>
</Window>
Le code behind :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Collections.ObjectModel;
 
namespace Raison2
{
    public partial class Window1 : Window
    {
        ObservableCollection<Synthetiseur> synth = new ObservableCollection<Synthetiseur>();
        public Window1()
        {
            InitializeComponent();
 
            DataContext = synth;
 
            synth.Add(new Synthetiseur("Moog", "paul",5));
            synth.Add(new Synthetiseur("Korg", "ici", 2));
            synth.Add(new Synthetiseur("DX7", "luc", 3));
        }
    }
}
et une petite class :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
 
namespace Raison2
{
    public class Synthetiseur : INotifyPropertyChanged
    {
        public Synthetiseur()
        { }
 
        public Synthetiseur(string nom, string fabriquant, int notation)
        {
            this.nom = nom;
            this.fabriquant = fabriquant;
            this.notation = notation;
        }
 
        private string nom;
 
        public string Nom
        {
            get { return nom; }
            set
            {
                nom = value;
                FirePropertyChanged("Nom");
            }
        }
 
        private string fabriquant;
 
        public string Fabriquant
        {
            get { return fabriquant; }
            set
            {
                fabriquant = value;
                FirePropertyChanged("Fabriquant");
            }
        }
 
        private int notation;
 
        public int Notation
        {
            get { return notation; }
            set
            {
                notation = value;
                FirePropertyChanged("Notation");
            }
 
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        public void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this,
                    new PropertyChangedEventArgs(propertyName));
        }
 
        public override string ToString()
        {
            return nom;
        }
    }
}