IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Problème liaison Classe [Débutant]


Sujet :

C#

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2015
    Messages : 10
    Points : 8
    Points
    8
    Par défaut Problème liaison Classe
    Bonjour a tous j'ai débuter en c# il y a quelques jours et je fais un petit exercice personnel je vous explique dans une grid j'ai une datagrid avec trois colonnes, un bouton supprimer (pour supprimer une ligne dans ma data), et un bouton ajouter (qui permet d'ajouter une ligne dans la data) dans une deuxième grid j'ai deux textbox nom/prénom une combobox ages de 0 à 100 et un bouton ajouter (griser tant que tout les champs ne sont pas remplies) j'aimerais lier ce qu'il y a dans ma deuxième grid à une classe 'Personne' et cette classe renvoie ce qu'il a enregistrer dans la datagrid

    Merci pour vos réponse.

  2. #2
    Membre actif
    Homme Profil pro
    Developpeur
    Inscrit en
    Février 2013
    Messages
    180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Developpeur

    Informations forums :
    Inscription : Février 2013
    Messages : 180
    Points : 271
    Points
    271
    Par défaut
    Bonjour,

    si j'ai bien compris vous avez deux Form, l'un avec un visuel Global et l'autre pour du détail
    Quand vous remplissez le détail, vous voulez que le global change. c'est bien ça ?

    si c'est le cas il vous faut une classe ou sont enregistré vos variable et dans la propriété Set de vos variable vous levez un evenement
    qui lancera une méthode de mise à jour de votre premier form

    Cordialement

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2015
    Messages : 10
    Points : 8
    Points
    8
    Par défaut
    Je n'ai pas vraiment compris votre question pour étres plus claire j'aimerais que les données qu'on inscrit dans les textbox (nom prénom) et dans la combo (pour l'âge) soit envoyer dans la classe personne et soit aussi dans la datagrid pour chaque colone respective

    voici l'xaml :

    Code XAML : 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
    <Window x:Class="projet3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <DataGrid x:Name="DGform" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="139,10,0,0" Height="130" Width="266" Cursor="Arrow" >
                <DataGrid.Columns>
                    <DataGridCheckBoxColumn x:Name="DGCBCnom" Binding="{Binding ElementName=TBnom, Mode=OneWay}" ClipboardContentBinding="{x:Null}" Header="Nom" MinWidth="100" SortDirection="Descending"/>
                    <DataGridCheckBoxColumn x:Name="DGCBCpre" Binding="{Binding ElementName=TBpren, Mode=OneWay}" ClipboardContentBinding="{x:Null}" Header="Prénom" MinWidth="100" SortDirection="Descending"/>
                    <DataGridCheckBoxColumn x:Name="DGCBCage" Binding="{Binding ElementName=CBage, Mode=OneWay}" ClipboardContentBinding="{x:Null}" Header="Age" MinWidth="70" SortDirection="Descending"/>
                </DataGrid.Columns>
                <DataGrid.Effect>
                    <DropShadowEffect/>
                </DataGrid.Effect>
            </DataGrid>
            <Button x:Name="BTadd" Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="34,24,0,0" Click="BTadd_Click"/>
            <Button x:Name="BTdel" Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="34,120,0,0" Click="BTdel_Click"/>
            <Button x:Name="BTmodif" Content="Modifier" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="33,71,0,0" IsEnabled="False"/>
            <Button x:Name="BTferm" Content="Fermer" HorizontalAlignment="Left" VerticalAlignment="Top" Width="168" Margin="185,289,0,0" Click="BTferm_Click"/>
            <Grid x:Name="GDcache" Margin="0,-16,0,0" Visibility="Hidden">
                <TextBox x:Name="TBnom" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Nom" VerticalAlignment="Top" Width="103" Margin="139,179,0,0"/>
                <TextBox x:Name="TBpren" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Prénom" VerticalAlignment="Top" Width="107" Margin="298,179,0,0"/>
                <ComboBox x:Name="CBage" HorizontalAlignment="Left" VerticalAlignment="Top" Width="171" Height="24" Margin="183,230,0,0" IsSynchronizedWithCurrentItem="True" Loaded="CBage_Loaded" SelectionChanged="CBage_SelectionChanged" Cursor="Arrow" Text="Veuillez entrer votre âges" IsEditable="True" IsReadOnly="True" />
                <Button x:Name="BTajout" Content="Ajouter" HorizontalAlignment="Left" VerticalAlignment="Top" Width="171" Margin="183,275,0,0" IsEnabled="False" RenderTransformOrigin="1.667,0.7" Click="BTajout_Click"/>
     
            </Grid>
        </Grid>
    </Window>

    le .cs

    Code C# : 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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
     
    namespace projet3
    {
        /// <summary>
        /// Logique d'interaction pour MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
     
            private void BTferm_Click(object sender, RoutedEventArgs e)
            {
                this.Close();
            }
     
            private void CBage_Loaded(object sender, RoutedEventArgs e)
            {
                for (int i = 0; i < 100; i++)
                {
                    CBage.Items.Add(i + 1);
                }
     
            }
     
            private void TBnom_TextChanged(object sender, TextChangedEventArgs e)
            {
                {
                    this.BTajout.IsEnabled = this.TBnom.Text.Length > 0;
                }
     
            }
     
            private void TBpren_TextChanged(object sender, TextChangedEventArgs e)
            {
                {
                    this.BTajout.IsEnabled = this.TBpren.Text.Length > 0;
                }
     
            }
     
            private void CBage_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
     
                this.BTajout.IsEnabled = this.CBage.SelectedIndex >= 0;
     
            }
     
            private void BTdel_Click(object sender, RoutedEventArgs e)
            {
                if (DGform.SelectedIndex != -1)
                {
     
                    DGform.Items.RemoveAt(DGform.SelectedIndex);
                }
            }
     
            private void BTadd_Click(object sender, RoutedEventArgs e)
            {
                GDcache.Visibility = Visibility.Visible;
            }
     
            private void BTajout_Click(object sender, RoutedEventArgs e)
            {
             DGform.ItemsSource = List<Personne>;
            }
        }
    }


    et la class personne :

    Code C# : 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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace projet3
    {
        class Personne
        {
            public string _nom;
            public string _prenom;
            public int _age; 
     
        }
    }
    Fichiers attachés Fichiers attachés

  4. #4
    Membre actif
    Homme Profil pro
    Developpeur
    Inscrit en
    Février 2013
    Messages
    180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Developpeur

    Informations forums :
    Inscription : Février 2013
    Messages : 180
    Points : 271
    Points
    271
    Par défaut
    voici comment doit être votre classe personne

    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
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace projet3
    {
    class Personne
    {
    //déclaration de tes evenement
    public event Action _monEvenement;
    private string _nom;
    private string _prenom;
    private int _age;
     
    public String Nom
            {
                get { return _nom; }
                set { _nom = value; }
            }
    public String Prenom
            {
                get { return _prenom; }
                set 
                { 
                      _prenom= value; 
                      //ici vous déclenchez votre evenement
                      raiseEvent _monEvent()
                }
            }
    public int Age
            {
                get { return _age; }
                set { _age= value; }
            }
     
    }
    }
    et ensuite dans le load de la fenetre ou tu veut effectuer un changement
    tu ajoute la ligne
    addhandler Personne._monEvent adressOf MaFonctionAExecuter();

    je t'encourage vivement à lire le cours de développez.com et les exemple de la msdn
    personnellement ces deux sites on réussit à me former sur le sujet

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème sur classe Transformer avec les <!--
    Par tykool dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 10/01/2006, 10h20
  2. Problème de classe
    Par DeusXL dans le forum DirectX
    Réponses: 15
    Dernier message: 04/12/2005, 14h37
  3. Problème de classe
    Par tidou dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 14/10/2005, 17h49
  4. problème Liaison ADOconnection avec AdoQuery
    Par Vodkha dans le forum Bases de données
    Réponses: 4
    Dernier message: 08/09/2005, 16h11
  5. [FLASH MX2004] Problème de classe
    Par JulPoWeR dans le forum Flash
    Réponses: 1
    Dernier message: 10/07/2005, 22h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo