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

Windows Presentation Foundation Discussion :

probleme de DataTemplate pour un treeview


Sujet :

Windows Presentation Foundation

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2004
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 62
    Points : 43
    Points
    43
    Par défaut probleme de DataTemplate pour un treeview
    Bonjour,

    J'ai une ObservableCollection sur un objet metier.
    Cet objet est clsZAC et il se compose ainsi
    1. ZACId = //id
    2. CMPId = //id de l'objet metier cmp
    3. VERId = //id de l'objet metier ver
    4. CMP = //instance de l'objet metier CMP
    5. VER = //instance de l'objet metier VER


    En fait ceci nous sert a dire la version de la competence technique d'un collaborateur.

    Le probleme :
    prenons exemple sur Visual Studio.
    Nous pouvons tres bien avoir dans un profil Visual Studio 2005 et 2008.
    Donc je veux faire afficher

    1. Visual Studion
      • 2005
      • 2008


    Mais actuellement ca affiche

    1. Visual Studio
      • 2005
    2. Visual Studio
      • 2008


    ce qui n'est pas tres beau.

    xaml :
    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
    <Window x:Class="WPFCVMANAGER.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:coll="clr-namespace:BUSINESSCOLLECTION;assembly=BUSINESSCOLLECTION"
        Title="Window1" Height="300" Width="300">
        <Window.Resources>
            <coll:clsZACCOLLECTION x:Key="col" x:Name="col"/>
            <DataTemplate x:Name="mtemplate" x:Key="mtemplate">
                <TreeViewItem IsExpanded="True">
                    <CheckBox Content="{Binding Path=CMP.CMPLibelle}" Tag="{Binding Path=CMP.CMPId}"></CheckBox>
                    <TreeViewItem IsExpanded="True">
                        <CheckBox Content="{Binding Path=VER.VERLibelle}" Tag="{Binding Path=VER.VERId}"></CheckBox>
                    </TreeViewItem>
                </TreeViewItem>
            </DataTemplate>
        </Window.Resources>
        <Grid DataContext="{StaticResource col}">
            <TreeView Margin="10,8,25,54" Name="treeView1" ItemsSource="{Binding}" ItemTemplate="{StaticResource mtemplate}">
     
            </TreeView>
        </Grid>
    </Window>
    Des idées ??

    Bon j'ai fait construit une classe Metier expres pour mon treeView. Cette classe contient le CMPLibelle et une List<clsZAC>. J'ai fait sa collection correspondante et j'ai changer mes binding path : Eh bien j'ai encore le probleme. En lisant sur le net je me suis rendu compte qu'il faudrait peut etre que j'utilise le HierarchicalDataTemplate. Donc j'ai modifier mon xaml en remplacant DataTemplate par HierarchicalDataTemplate et ca ne fonctionne toujours pas.

    Voici le nouveau xaml :

    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
    <Window x:Class="WPFCVMANAGER.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:coll="clr-namespace:BUSINESSCOLLECTION;assembly=BUSINESSCOLLECTION"
        Title="Window1" Height="300" Width="300">
        <Window.Resources>        
            <coll:clsZAC_GROUPBYCMPCOLLECTION x:Key="col"/>
            <HierarchicalDataTemplate  x:Name="mtemplate" x:Key="mtemplate">
                <TreeViewItem IsExpanded="True">
                    <CheckBox Content="{Binding Path=CMPLibelle}"></CheckBox>
                    <TreeViewItem IsExpanded="True">
                        <CheckBox Content="{Binding Path=ZAC.VER.VERLibelle}" Tag="{Binding Path=ZAC.VER.VERId}"></CheckBox> //ce check box n'affiche plus rien
                    </TreeViewItem>
                </TreeViewItem>
            </HierarchicalDataTemplate >
        </Window.Resources>
        <Grid DataContext="{StaticResource col}">
            <TreeView Margin="10,8,25,54" Name="treeView1" ItemsSource="{Binding}" ItemTemplate="{StaticResource mtemplate}">
                        
            </TreeView>
        </Grid>
    </Window>
    Pouvez vous me dire ce qui ne va pas s'il vous plait car je commence a me sentir rejeté par WPF.

    Merci
    Pascal Wick
    Groupe OnePoint
    Pascal Wick
    Programmeur-Analyste Sr.

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Février 2004
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 62
    Points : 43
    Points
    43
    Par défaut Classe métier
    COLLECTION :
    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
     
    public class clsZAC_GROUPBYCMPCOLLECTION : ObservableCollection<clsZAC_GroupByCMP>
        {
            public clsZAC_GROUPBYCMPCOLLECTION()
                : base()
            {
                DataTable tbl = clsCrud.GetCrud().BaseCrud.TBLZac;
                tbl.DefaultView.Sort = "CMP_ID";
     
                for (int k = 0; k < tbl.DefaultView.Count; k++)
                {
                    Add(new clsZAC_GroupByCMP(long.Parse(tbl.DefaultView.ToTable().Rows[k]["CMP_ID"].ToString())));
                }
            }
        }
    METIER

    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
    public class clsZAC_GroupByCMP : DependencyObject
        {
            public clsZAC_GroupByCMP(long CMPId)
                : base()
            {
                DataRow[] rZAC = clsCrud.GetCrud().BaseCrud.TBLZac.Select("CMP_ID = " + CMPId);
                List<clsZAC> lZAC = new List<clsZAC>();
                for (int k = 0; k < rZAC.Length; k++)
                {
                    if (k == 0)
                        CMPLibelle = clsZAC.GetBusinessObjectByDataRow((DATA_ACCESS.DTS_CVMANAGER.ZAC_CMP_VERRow)rZAC[k]).CMP.CMPLibelle;
     
                    lZAC.Add(clsZAC.GetBusinessObjectByDataRow((DATA_ACCESS.DTS_CVMANAGER.ZAC_CMP_VERRow)rZAC[k]));
                }
                ZAC = lZAC;
     
            }
     
            public static DependencyProperty CMPLibelleProperty = DependencyProperty.Register("CMPLibelle", typeof(string), typeof(clsZAC_GroupByCMP));
            public static DependencyProperty ZACProperty = DependencyProperty.Register("ZAC", typeof(List<clsZAC>), typeof(clsZAC_GroupByCMP));
     
            public List<clsZAC> ZAC
            {
                get { return (List<clsZAC>)GetValue(ZACProperty); }
                set { SetValue(ZACProperty, value); }
            }
            public string CMPLibelle
            {
                get { return (string)GetValue(CMPLibelleProperty); }
                set { SetValue(CMPLibelleProperty, value); }
            }
        }
    Groupe OnePoint
    Pascal Wick
    Programmeur-Analyste Sr.

  3. #3
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Points : 1 313
    Points
    1 313
    Par défaut
    c'est quoi la clsZACCOLLECTION ?
    IKEAS : Finalement je crois que c'est dans ses faiblesses que l'on y trouve a la fois de la force et a la fois de la richesse...
    ----------------------------------------------------
    Si vous avez du taf en wpf & design d'application sympa, contactez moi !!!!
    http://ultimatecorp.eu/wpf/

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Février 2004
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 62
    Points : 43
    Points
    43
    Par défaut ClsZACCOLLECTION et clsZAC
    clsZACCOLLECTION :

    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
    public class clsZACCOLLECTION : ObservableCollection<clsZAC>
        {
            DataRow[] r;
            private void AddRows(DataRow[] rows)
            {
                for (int k = 0; k < rows.Length; k++)
                    Add(clsZAC.GetBusinessObjectByDataRow((DATA_ACCESS.DTS_CVMANAGER.ZAC_CMP_VERRow)rows[k]));
            }
            private void AddRows(DataView dv)
            {
                AddRows(dv.ToTable().Select());            
            }
            public clsZACCOLLECTION()
                : base()
            {
                r = clsCrud.GetCrud().BaseCrud.TBLZac.Select();
                AddRows(r);
            }
            public clsZACCOLLECTION(long ID, bool isCMPId) : base()
            {
                DataRow[] r;
                if (isCMPId)
                    r = clsCrud.GetCrud().BaseCrud.TBLZac.Select("CMP_ID = " + ID.ToString());
                else
                    r = clsCrud.GetCrud().BaseCrud.TBLZac.Select("VER_ID = " + ID.ToString());
                AddRows(r);
            }
            public clsZACCOLLECTION(bool OrderByCMPId) : base()
            {
                if (OrderByCMPId)
                {
                    DataTable tbl = clsCrud.GetCrud().BaseCrud.TBLZac;
                    tbl.DefaultView.RowFilter = "CMP_ID";
                    AddRows(tbl.DefaultView);
                }
                else
                {
                    r = clsCrud.GetCrud().BaseCrud.TBLZac.Select();
                    AddRows(r);
                }
            }
        }
    }
    clsZAC :
    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
    72
    public class clsZAC : DependencyObject
        {
            private long _lngZACId, _lngVERId, _lngCMPId;
     
            public static DependencyProperty ZACIdProperty = DependencyProperty.Register("ZACId", typeof(long), typeof(clsZAC));
            public static DependencyProperty VERIdProperty = DependencyProperty.Register("VERId", typeof(long), typeof(clsZAC));
            public static DependencyProperty CMPIdProperty = DependencyProperty.Register("CMPId", typeof(long), typeof(clsZAC));
            public static DependencyProperty VERProperty = DependencyProperty.Register("VER", typeof(clsVER), typeof(clsZAC));
            public static DependencyProperty CMPProperty = DependencyProperty.Register("CMP", typeof(clsCMP), typeof(clsZAC));
     
            public clsZAC() : base()
            {
                ZACId = -1;
            }
     
            public long ZACId
            {
                get { return (long)GetValue(ZACIdProperty); }
                set { SetValue(ZACIdProperty, value); }
            }
            public long CMPId
            {
                get { return (long)GetValue(CMPIdProperty); }
                set 
                { 
                    SetValue(CMPIdProperty, value);
                    SetValue(CMPProperty, clsCMP.GetBusinessObjectByDataRow(clsCrud.GetCrud().SelectCMPbyId(value)));
                }
            }
            public long VERId
            {
                get { return (long)GetValue(VERIdProperty); }
                set 
                { 
                    SetValue(VERIdProperty, value);
                    SetValue(VERProperty, clsVER.GetBusinessObjectByDataRow(clsCrud.GetCrud().SelectVERbyId(value)));
                }
            }
            public clsVER VER
            {
                get { return (clsVER)GetValue(VERProperty); }
                set
                {
                    SetValue(VERProperty, value);
                    SetValue(VERIdProperty, value.VERId);
                }
            }
            public clsCMP CMP
            {
                get { return (clsCMP)GetValue(CMPProperty); }
                set
                {
                    SetValue(CMPProperty, value);
                    SetValue(CMPIdProperty, value.CMPId);
                }
            }
            /// <summary>
            /// retourne un objet de cette classe en fonction de la DataRow passer en parametre
            /// </summary>
            /// <param name="r"></param>
            /// <param name="crud"></param>
            /// <returns></returns>
            public static clsZAC GetBusinessObjectByDataRow(DATA_ACCESS.DTS_CVMANAGER.ZAC_CMP_VERRow r)
            {
                if (r != null)
                {
                    return new clsZAC() { CMPId = r.CMP_ID, VERId = r.VER_ID, ZACId = r.ZAC_ID };
                }
                else
                    return null;
            }
        }
    Groupe OnePoint
    Pascal Wick
    Programmeur-Analyste Sr.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Février 2004
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 62
    Points : 43
    Points
    43
    Par défaut J'ai compris
    Ok le probleme est résolu. C'est moi qui avait mal monter ma collection donc c'etais normal.
    Groupe OnePoint
    Pascal Wick
    Programmeur-Analyste Sr.

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

Discussions similaires

  1. Probleme de conception pour un update Oracle!
    Par vempiria dans le forum Langage SQL
    Réponses: 3
    Dernier message: 27/09/2005, 10h28
  2. Probleme avec ODBC pour la V8.
    Par chad33 dans le forum PostgreSQL
    Réponses: 2
    Dernier message: 04/03/2005, 23h57
  3. Réponses: 3
    Dernier message: 24/02/2005, 15h48
  4. Réponses: 2
    Dernier message: 01/06/2004, 16h12
  5. où y a t il un tutorial pour le Treeview ??
    Par silvermoon dans le forum C++Builder
    Réponses: 4
    Dernier message: 09/12/2002, 13h30

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