Lier un DataGridView à un déplacement dans la Base de Données

Résolu
warzet Messages postés 44 Date d'inscription lundi 27 août 2007 Statut Membre Dernière intervention 1 novembre 2016 - 19 sept. 2013 à 11:13
dodo7263 Messages postés 614 Date d'inscription mercredi 10 septembre 2008 Statut Membre Dernière intervention 9 février 2017 - 8 oct. 2013 à 15:57
Bonjour à tous,
j'ai une grosse difficulté que je cherche à surmonter, trouver le titre a été un problème. Voilà, j'ai des enregistrements que j'affiche dans des textbox et dans un datagridview, j'ai des boutons de commande pour me déplacer, en avant , en arrière: mon souhait est de pouvoir déplacer le curseur du DataGridView sur l'enregistrement correspondant lorsque je Click sur un des boutons de déplacement dans les enregistrements.
Le Code d'un de mes boutons de navigation est le suivant:
        private void Click_Suivant(object sender, EventArgs e)
        {
            try
            {
                if (i < iMax)
                {
                    //Passage à l'Elève suivant
                    i++;
                    //Refresh du propect et du label
                    Label_Effectif();
                    Afficher();
                    //this.dgvEleves.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvEleves_CellClick);
                    //this.dgvEleves.Capture += this.dgvEleves_CellClick(object sender, DataGridViewCellEventArgs e);
                }
                else
                {
                    MessageBox.Show("Vous êtes en Fin de Liste", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Concat("Erreur: ", ex.Message));
            }
        }


Le code du click dans le DataGridView

        private void dgvEleves_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            this.txtCodeEleve.Text = this.dgvEleves.CurrentRow.Cells[0].Value.ToString();
            this.txtNomEleve.Text = this.dgvEleves.CurrentRow.Cells[1].Value.ToString();
            this.txtPrenomEleve.Text = this.dgvEleves.CurrentRow.Cells[2].Value.ToString();
            this.txtSexe.Text = this.dgvEleves.CurrentRow.Cells[3].Value.ToString();
            this.txtDateNaissance.Text = this.dgvEleves.CurrentRow.Cells[4].Value.ToString();
            this.txtLieuNaissance.Text = this.dgvEleves.CurrentRow.Cells[5].Value.ToString();
            this.txtNationalite.Text = this.dgvEleves.CurrentRow.Cells[6].Value.ToString();
            this.txtNomPere.Text = this.dgvEleves.CurrentRow.Cells[7].Value.ToString();
            this.txtNomMere.Text = this.dgvEleves.CurrentRow.Cells[8].Value.ToString();
            this.txtTuteur.Text = this.dgvEleves.CurrentRow.Cells[9].Value.ToString();
            this.txtFonction.Text = this.dgvEleves.CurrentRow.Cells[10].Value.ToString();
            this.txtAdresse.Text = this.dgvEleves.CurrentRow.Cells[11].Value.ToString();
            this.txtTelephone.Text = this.dgvEleves.CurrentRow.Cells[12].Value.ToString();
            this.txtClasse.Text = this.dgvEleves.CurrentRow.Cells[13].Value.ToString();
            this.txtDateInscription.Text = this.dgvEleves.CurrentRow.Cells[14].Value.ToString();
            this.txtAnneeScolaire.Text = this.dgvEleves.CurrentRow.Cells[15].Value.ToString();
            this.txtEcole.Text = this.dgvEleves.CurrentRow.Cells[16].Value.ToString();
            this.txtExClasse.Text = this.dgvEleves.CurrentRow.Cells[17].Value.ToString();
            this.txtExAnnee.Text = this.dgvEleves.CurrentRow.Cells[18].Value.ToString();
            this.txtDoublant.Text = this.dgvEleves.CurrentRow.Cells[19].Value.ToString();
            this.txtMoyenne.Text = this.dgvEleves.CurrentRow.Cells[20].Value.ToString();
            this.txtDiplome.Text = this.dgvEleves.CurrentRow.Cells[21].Value.ToString();
            this.txtStatut.Text = this.dgvEleves.CurrentRow.Cells[22].Value.ToString();
            this.txtDecision.Text = this.dgvEleves.CurrentRow.Cells[23].Value.ToString();
            this.txtRegime.Text = this.dgvEleves.CurrentRow.Cells[25].Value.ToString();
            this.txtTransfert.Text = this.dgvEleves.CurrentRow.Cells[26].Value.ToString();
        }


Comment faire, aidez moi.

6 réponses

dodo7263 Messages postés 614 Date d'inscription mercredi 10 septembre 2008 Statut Membre Dernière intervention 9 février 2017 6
19 sept. 2013 à 11:31
Salut,

Excuse moi mais je n'ai pas bien compris ce que tu cherches à faire ni ton problème si problème il y a.
Lorsque tu cliques sur ton bouton suivant ça fonctionne ou non ?
Tes textbox ne se remplissent pas ?

@++
0
warzet Messages postés 44 Date d'inscription lundi 27 août 2007 Statut Membre Dernière intervention 1 novembre 2016
19 sept. 2013 à 11:43
Merci pour ta réponse,
Lorsque je click sur l'un des mes boutons, je me déplace normalement, mais je souhaite lier ce déplacement au mouvement du curseur de mon DataGridView, qu'il affiche l'enregistrement correspondant.
0
dodo7263 Messages postés 614 Date d'inscription mercredi 10 septembre 2008 Statut Membre Dernière intervention 9 février 2017 6
25 sept. 2013 à 21:53
Re,

Désolé pour mon temps de réponse mais as tu essayé d'utiliser l'événement selectionChanged de ton datatgridview.

private void dgvEleves_SelectionChanged(object sender, EventArgs e)
{

            this.txtCodeEleve.Text = this.dgvEleves.CurrentRow.Cells[0].Value.ToString();
            this.txtNomEleve.Text = this.dgvEleves.CurrentRow.Cells[1].Value.ToString();
            this.txtPrenomEleve.Text = this.dgvEleves.CurrentRow.Cells[2].Value.ToString();
            this.txtSexe.Text = this.dgvEleves.CurrentRow.Cells[3].Value.ToString();
            this.txtDateNaissance.Text = this.dgvEleves.CurrentRow.Cells[4].Value.ToString();
            this.txtLieuNaissance.Text = this.dgvEleves.CurrentRow.Cells[5].Value.ToString();
            this.txtNationalite.Text = this.dgvEleves.CurrentRow.Cells[6].Value.ToString();
            this.txtNomPere.Text = this.dgvEleves.CurrentRow.Cells[7].Value.ToString();
            this.txtNomMere.Text = this.dgvEleves.CurrentRow.Cells[8].Value.ToString();
            this.txtTuteur.Text = this.dgvEleves.CurrentRow.Cells[9].Value.ToString();
            this.txtFonction.Text = this.dgvEleves.CurrentRow.Cells[10].Value.ToString();
            this.txtAdresse.Text = this.dgvEleves.CurrentRow.Cells[11].Value.ToString();
            this.txtTelephone.Text = this.dgvEleves.CurrentRow.Cells[12].Value.ToString();
            this.txtClasse.Text = this.dgvEleves.CurrentRow.Cells[13].Value.ToString();
            this.txtDateInscription.Text = this.dgvEleves.CurrentRow.Cells[14].Value.ToString();
            this.txtAnneeScolaire.Text = this.dgvEleves.CurrentRow.Cells[15].Value.ToString();
            this.txtEcole.Text = this.dgvEleves.CurrentRow.Cells[16].Value.ToString();
            this.txtExClasse.Text = this.dgvEleves.CurrentRow.Cells[17].Value.ToString();
            this.txtExAnnee.Text = this.dgvEleves.CurrentRow.Cells[18].Value.ToString();
            this.txtDoublant.Text = this.dgvEleves.CurrentRow.Cells[19].Value.ToString();
            this.txtMoyenne.Text = this.dgvEleves.CurrentRow.Cells[20].Value.ToString();
            this.txtDiplome.Text = this.dgvEleves.CurrentRow.Cells[21].Value.ToString();
            this.txtStatut.Text = this.dgvEleves.CurrentRow.Cells[22].Value.ToString();
            this.txtDecision.Text = this.dgvEleves.CurrentRow.Cells[23].Value.ToString();
            this.txtRegime.Text = this.dgvEleves.CurrentRow.Cells[25].Value.ToString();
            this.txtTransfert.Text = this.dgvEleves.CurrentRow.Cells[26].Value.ToString();
        }


@++
0
warzet Messages postés 44 Date d'inscription lundi 27 août 2007 Statut Membre Dernière intervention 1 novembre 2016
28 sept. 2013 à 11:00
Merci une fois encore, mais ce que je souhaite, c'est d'avoir la ligne de mon DataGridView en surbrillance correspondant à l'neregistrement affiché dans les textBox, et cela à chaque changement d'affichage. Merci encore
0
dodo7263 Messages postés 614 Date d'inscription mercredi 10 septembre 2008 Statut Membre Dernière intervention 9 février 2017 6
28 sept. 2013 à 11:07
Salut,

dans ton bouton de déplacement essais ceci :

datagridview.CurrentCell = datagridview.Rows[rowIndex].Cells[0];
datagridview.Rows[rowIndex].Selected = true;


@++
0
warzet Messages postés 44 Date d'inscription lundi 27 août 2007 Statut Membre Dernière intervention 1 novembre 2016
8 oct. 2013 à 12:18
Merci à toi Dodo ce bout de code fait absolument mon affaire
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Whismeril Messages postés 19025 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 19 avril 2024 656
28 sept. 2013 à 21:19
Bonsoir,

ceci peut correspondre à ton besoin.
0
warzet Messages postés 44 Date d'inscription lundi 27 août 2007 Statut Membre Dernière intervention 1 novembre 2016
8 oct. 2013 à 12:20
Merci à vous tous pour votre précieuse aide, en particulier Dodo7263 dont le dernier bout de code a fait exactement ce que je souhaitais. Merci
0
dodo7263 Messages postés 614 Date d'inscription mercredi 10 septembre 2008 Statut Membre Dernière intervention 9 février 2017 6
8 oct. 2013 à 15:57
Si ça te convient n'oublie pas de passer ton sujet en résolu ;-)
0
Rejoignez-nous