[C# .NET 2.0] Problème de fermeture avec ShowDialog()
Bonjour,
Voici mon problème:
A partir d'un formulaire (frmClients), j'appelle l'ouverture d'un autre formulaire (frmRecherche) avec la méthode ShowDialog(). Celui-ci s'ouvre correctement et m'affiche la liste demandée grâce au datagrid (dtgRecherche) qui s'y trouve.
En double-cliquant sur une des lignes de mon datagrig, je renvoie une donnée au formulaire appelant (frmClient) et demande la fermeture de mon formulaire de recherche via la commande "this.Close()". J'y ai installé aussi un bouton "Annuler" qui ferme le formulaire sans rien renvoyer.
Mais voilà, il faut que je double-clique 2 fois pour qu'il se ferme et de même si je veux annuler, je dois appuyer 2 fois aussi sur le bouton pour obtenir la procédure de fermeture !!!
Voici le code du formulaire appelant:
Code:
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
|
private void Barre_de_navigation1_clickBtnSearch(object sender, CtlNavigationEvent e)
{
frmRecherche noRecherche = new frmRecherche();
switch (sCatégorie)
{
case "Particuliers":
maVue = Barre_de_navigation1.dsRecherche.Tables["RechercheParticuliers"].DefaultView;
noRecherche.dtgRecherche.DataSource = maVue;
break;
case "HoReCa":
maVue = Barre_de_navigation1.dsRecherche.Tables["RechercheHoReCa"].DefaultView;
noRecherche.dtgRecherche.DataSource = maVue;
break;
case "Grossistes":
maVue = Barre_de_navigation1.dsRecherche.Tables["RechercheGrossistes"].DefaultView;
noRecherche.dtgRecherche.DataSource = maVue;
break;
}
noRecherche.dtgRecherche.Columns["NumIDClient"].Width = 80;
noRecherche.dtgRecherche.Columns["NumIDClient"].HeaderText = "ID Client";
noRecherche.dtgRecherche.Columns["Société"].Width = 180;
noRecherche.dtgRecherche.Columns["Prénom"].Width = 80;
noRecherche.dtgRecherche.Columns["Nom"].Width = 150;
noRecherche.dtgRecherche.Columns["Adresse"].Width = 180;
noRecherche.dtgRecherche.Columns["Code_postal"].Width = 60;
noRecherche.dtgRecherche.Columns["Code_postal"].HeaderText = "CP";
noRecherche.dtgRecherche.Columns["Ville"].Width = 150;
noRecherche.ShowDialog();
if (noRecherche.monID != "")
{
for (int i = 0; i < Barre_de_navigation1.dsPrincipal.Tables[sCatégorie].Rows.Count; i++)
{
if (Barre_de_navigation1.dsPrincipal.Tables[sCatégorie].Rows[i]["NumIDClient"].ToString() == noRecherche.monID)
{
e.iPosEnreg = i;
nettoyerChamps();
afficherDonnées(Barre_de_navigation1.dsPrincipal, e.iPosEnreg);
break;
}
}
}
noRecherche.Dispose();
noRecherche = null;
} |
Et celui du formulaire appelé:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| private void dtgRecherche_DoubleClick(object sender, EventArgs e)
{
DataGridViewCell clickedCell;
int X = 0;
int Y = dtgRecherche.CurrentCell.RowIndex;
clickedCell = dtgRecherche.Rows[Y].Cells[X];
_monID = clickedCell.Value.ToString();
if (_monID != "") this.Close();
}
private void btnAnnuler_Click(object sender, EventArgs e)
{
_monID = "";
this.Close();
}
private void frmRecherche_Load(object sender, EventArgs e)
{
dtgRecherche.RowHeadersVisible = false;
dtgRecherche.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dtgRecherche.MultiSelect = false;
dtgRecherche.BackgroundColor = Color.Maroon;
} |
Quelqu'un pourrait-il m'expliquer ce qui se passe ?
Merci d'avance.