Bonjour à tous !
Je m'explique.
J'ai créé 2 UserControl, dans un j'ai une Texbox (Box_Recherche) et un Bouton (Bouton_Recherche)
Dans l'autre j'ai deux TextBox (Box_Box_Numero_Tel et Box_Nom)
Dans le MainWindow j'ai inclus ces deux UserControl
1 2 3 4 5 6 7
| <Grid Name="Recherche" Grid.Row="1" Grid.Column="1" Grid.RowSpan="1" Grid.ColumnSpan="1">
<local:Recherche DataContext="{Binding}"/>
</Grid>
<Grid Name="Information" Grid.Row="2" Grid.Column="1" Grid.RowSpan="1" Grid.ColumnSpan="1">
<local:Information DataContext="{Binding}"/>
</Grid> |
Maintenant j'aimerai que lorsque je fait ma recherche au clique, la valeur de Box_Recherche se mette aussi dans Box_Numero_Tel du deuxième UserControl.
Pour info, je récupère ses valeurs dans un fichier Excel.
UserControl Recheche :
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
| string sourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\username\Desktop\BDD.xlsx';Extended Properties='excel 8.0;HDR=Yes;IMEX=1'";
Information information = new Information();
try
{
OleDbConnection Connexion = new OleDbConnection(sourceConstr);
Connexion.Open();
OleDbCommand cmd = new OleDbCommand("select * from [Feuil1$] where ["Telephone"]= '" + Box_Recherche.Text + "'", Connexion);
OleDbDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
information.Box_Numero_Tel.Text = dr[0].ToString();
information.Box_Nom.Text = dr[1].ToString();
}
else
{
MessageBox.Show("Numéro incorrect ou inconnu dans la base de donnée.", "Information manquante", MessageBoxButton.OK, MessageBoxImage.Information);
}
Connexion.Close();
}
catch
{
MessageBox.Show("Impossible de se connecter à la base de donnée. Veuillez réessayer", "Erreur BDD", MessageBoxButton.OK, MessageBoxImage.Information);
} |
J'ai essayé de déclarer mes variables dans "Information" comme ci-dessous. Pour ensuite faire
information.Telephone = dr[0].ToString();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public partial class Information : UserControl
{
public string Nom
{
get => Nom;
set => Nom = value;
}
public string Telephone
{
get => Telephone;
set => Telephone= value;
}
public Information()
{
InitializeComponent();
}
} |
Le problème c'est qu'il faudrait créer un Event dans "Information" pour déclarer que mes variables sont égales à mes TextBox.
Je pense que ma logique n'est pas bonne mais je ne sais pas ou.
Merci d'avance pour vos réponses.
Partager