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 :

binder listbox et datagridview chacun ayant relier à une table differente


Sujet :

Windows Presentation Foundation

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 10
    Par défaut binder listbox et datagridview chacun ayant relier à une table differente
    Bonjour,

    Je souhaite binder une listbox à un datagridview

    La listbox fait référence à une table: TABLE_CHANTIER
    Le datagridview fait référence à une table TABLE_TOUPIE (c'est des camions de livraison de béton pour info...)

    Chaque table contient un champ NUM_CAMION

    Je voudrais donc que quand je clique sur un chantier dans la listbox, la liste des camions associés apparaisse dans le datagridview...

    Le problème est que je ne sait pas comment faire pour remplir mon dataset correctement...

    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
        Private Sub TabGestion_Chantier_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles TabGestion_Chantier.Loaded
            'strConn = "provider=microsoft.jet.oledb.4.0;" & "Data Source= c:\base.mdb;"
            'strConn = "provider=microsoft.jet.oledb.4.0;" & "Data Source= " & AppDomain.CurrentDomain.BaseDirectory & "\base.mdb;"
            strConn = "provider=microsoft.jet.oledb.4.0;" & "Data Source= " & My.Application.Info.DirectoryPath & "\base.mdb;"
     
            'strSql = "SELECT TABLE_CHANTIER.* FROM TABLE_CHANTIER"
            strSql = "SELECT * FROM TABLE_CHANTIER"
     
            ObjetConnection = New OleDbConnection
            ObjetConnection.ConnectionString = strConn
            ObjetConnection.Open()
     
            ObjetCommand = New OleDbCommand(strSql)
            ObjetDataAdapter = New OleDbDataAdapter(ObjetCommand)
            ObjetCommand.Connection() = ObjetConnection
            ObjetDataAdapter.Fill(ObjetDataSet, "TABLE_CHANTIER")
            DataContext = ObjetDataSet
     
        End Sub
    Code 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
    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    <Window x:Class="Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
        Title="Window1" Height="500" Width="800" WindowState="maximized" >
     
        <Window.Resources>
            <Style x:Key="Lecture_Seule" TargetType="{x:Type TextBox}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=_CheckBox_Lecture_Seule, Path=IsChecked}" Value="True">
                        <Setter Property="TextBox.IsEnabled" Value="False"/>
                        <Setter Property="TextBox.BorderThickness" Value="0"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ElementName=_CheckBox_Lecture_Seule, Path=IsChecked}" Value="False">
                        <Setter Property="TextBox.IsEnabled" Value="True"/>
                        <Setter Property="TextBox.BorderThickness" Value="2"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
     
            <DataTemplate x:Key="Mise_en_forme_liste">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="10" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition Height="10"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Path=NOM_CHANTIER}" Grid.Column="0" FontWeight="bold" />
                    <TextBlock Name="_TextBlock1" Text="{Binding Path=NOM_CLIENT}" Grid.Row="1"  FontSize="9"/>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Path=NOM_CLIENT}" Value="EBN PERIERS">
                        <Setter TargetName="_TextBlock1" Property="Foreground" Value="Red" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=NOM_CLIENT}" Value="ROL NORMANDIE GRAN.">
                        <Setter TargetName="_TextBlock1" Property="Foreground" Value="Blue" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </Window.Resources>
     
        <Grid>
            <TabControl Margin="3,3,3,3" Name="TabControl_Principal" >
                <TabItem Header="Gestion Chantier" Name="TabGestion_Chantier">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="250" />
                            <ColumnDefinition Width="7" />
                            <ColumnDefinition  />    
                        </Grid.ColumnDefinitions>
                        <ListBox Grid.Column="0" 
                                 Margin="14,28,14,10" 
                                 Name="ListBox1"
                                 ItemsSource="{Binding TABLE_CHANTIER, Mode=Default}"
                                 ItemTemplate="{StaticResource Mise_en_forme_liste}"
                                 IsSynchronizedWithCurrentItem="true"
                                 />
                        <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" >
                        	<GridSplitter.Background>
                        		<SolidColorBrush Color="#FFF6D4C4"/>
                        	</GridSplitter.Background>
                        </GridSplitter>
     
     
                        <Grid Grid.Column="2" Height="112.716" VerticalAlignment="Top" Margin="8.6,0,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="180" />
                                <ColumnDefinition Width="10" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="28" />
                                <RowDefinition Height="28" />
                                <RowDefinition Height="28" />
                            </Grid.RowDefinitions>
     
                            <Label Name="Label1" Margin="38.642,0,0,0">Equipe:</Label>
                            <TextBox    Name="txtselection1" Grid.Column="2" Grid.Row="0"                            
                                        VerticalAlignment="Center"
                                        Text="{Binding ElementName=ListBox1, Path=SelectedItem.NOM_EQUIPE, Mode=Twoway}"
                                        Style="{StaticResource Lecture_Seule}" />
     
                            <Label Grid.Row="1" Name="Label2" Margin="38.642,0,0,0">Nom du chantier:</Label>
                            <TextBox    Name="txtselection2" Grid.Column="2" Grid.Row="1"                            
                                        VerticalAlignment="Center"
                                        Text="{Binding ElementName=ListBox1, Path=SelectedItem.NOM_CHANTIER, Mode=Twoway}"
                                        Style="{StaticResource Lecture_Seule}"/>
     
                            <Label Grid.Row="2" Name="Label3" Margin="38.642,0,0,0">Date de demarrage:</Label>
                            <TextBox    Name="txtselection3" Grid.Column="2" Grid.Row="2"                            
                                        VerticalAlignment="Center"
                                        Text="{Binding ElementName=ListBox1, Path=SelectedItem.DATE_DEMARRAGE, Mode=Twoway}" 
                                        Style="{StaticResource Lecture_Seule}"/>
                        </Grid>    
     
                        <CheckBox x:Name="_CheckBox_Lecture_Seule" Grid.Column="2" Height="20.006" Margin="47.242,132,0,0" Content="Lecture seule" 
                                  VerticalAlignment="Top" HorizontalAlignment="Left" Width="138.164"/>
     
                        <dg:DataGrid IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=TABLE_TOUPIE}"  Grid.Column="2" Margin="0,159.984,0,169.983" />
     
     
                    </Grid>
     
                </TabItem>
     
            </TabControl>
        </Grid>
    Voili, voilou,

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Février 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 10
    Par défaut
    En relisant ma question je m'aperçois que la question n'est pas forcément très clair


    En fait pour le moment j'ai bindé une listbox sur une table d'une base access. J'affiche les infos que je souhaite grâce à un datatemplate. (Merci les tutos...)

    Ensuite voulant réaliser une vue maitre/détail, j'ai binder des textbox sur la lisbox pour afficher des infos supplémentaires (détails) mais de la même table.
    Jusque la pas de problème (merci les tutos)

    Maintenant je voudrais compléter ma vue détail par des infos d'une autre table sous forme d'un datagrid. là ça se corse.

    Ah mon sens il faut se connecté à la table supplémentaire et effectuer un filtre suivant la donnée sélectionnée dans la lisbox... mais je ne voit pas du tout comment faire, d'une part pour créer le datacontext, ensuite pour réaliser le filtre ou le binding....

    j' ai bien trouver un tuto qui parle de INNER JOIN ON mais je ne vois pas comment le maitre en oeuvre dans ce projet

    merci à vous

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Février 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 10
    Par défaut
    Je me permet de réouvrir ce post pour donner la solution qui a été résolu à ce post:

    http://www.developpez.net/forums/d89...ation-binding/

    Le principe est exactement le même

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

Discussions similaires

  1. [WD15] Relier une table a un tableau
    Par GDev80 dans le forum WinDev
    Réponses: 9
    Dernier message: 10/11/2011, 15h52
  2. [MySQL] Relier une table avec un système de recherche d'adresse
    Par cool-man dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 28/09/2010, 16h05
  3. COUNT sur une table differente.
    Par Havocks dans le forum Langage SQL
    Réponses: 2
    Dernier message: 29/07/2008, 15h27
  4. comment relier une table qui a deux maîtres
    Par tchimou dans le forum Bases de données
    Réponses: 7
    Dernier message: 07/05/2007, 20h15

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