//Code pour le precedent (dg etant ta datagrid) try { dg.UnSelect(dg.CurrentRowIndex); int position = dg.CurrentRowIndex - 1; if(position < 0) { position = 0; } dg.CurrentRowIndex = position; dg.Select(dg.CurrentRowIndex) } catch { } //Code pour le suivant try { dg.UnSelect(dg.CurrentRowIndex); int nb_ligne = ((System.Data.DataTable) dg.DataSource).Rows.Count; int position = dg.CurrentRowIndex + 1; if(position > nb_ligne) { position = nb_ligne - 1; } dg.CurrentRowIndex = position; dg.Select(dg.CurrentRowIndex); } catch { }
//Databinding sur les textbox Binding Bind_Compteur = new Binding("Text", ds.Tables["MA_TABLE"], "NOm_CHAMP_COMPTEUR); Binding Bind_Code = new Binding("Text", ds.Tables["MA_TABLE"], "NOM_CHAMP_CODE); txt_compteur.DataBindings.Add( Bind_Compteur ); txt_code.DataBindings.Add( Bind_Code );
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiontxt_code.DataBindings["Text"].BindingManagerBase.EndCurrentEdit(); txt_compteur.DataBindings["Text"].BindingManagerBase.EndCurrentEdit(); //Autant de fois que du a de binding sur tes textbox, ca force le dataset a prendre les infos saisie dans les textbox....
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; namespace Test_Mysql { /// <summary> /// Description résumée de Form3. /// </summary> public class Form3 : System.Windows.Forms.Form { private System.Windows.Forms.DataGrid dataGrid1; private System.Windows.Forms.Button button1; /// <summary> /// Variable nécessaire au concepteur. /// </summary> private System.ComponentModel.Container components = null; //DECLARATION DU DATASET private DataSet ds = new DataSet(); //CONNECTION private SqlConnection MaConnect; //Objet Command private SqlCommand MaCmdSelect; //DATAADAPTER private SqlDataAdapter MonDataAdapter; public Form3() { // // Requis pour la prise en charge du Concepteur Windows Forms // InitializeComponent(); // // TODO : ajoutez le code du constructeur après l'appel à InitializeComponent // } /// <summary> /// Nettoyage des ressources utilisées. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Code généré par le Concepteur Windows Form /// <summary> /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas /// le contenu de cette méthode avec l'éditeur de code. /// </summary> private void InitializeComponent() { this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.button1 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(8, 8); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(592, 440); this.dataGrid1.TabIndex = 0; // // button1 // this.button1.Location = new System.Drawing.Point(608, 16); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 64); this.button1.TabIndex = 1; this.button1.Text = "Charge la liste des medecin"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form3 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(696, 462); this.Controls.Add(this.button1); this.Controls.Add(this.dataGrid1); this.Name = "Form3"; this.Text = "Form3"; ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.ResumeLayout(false); } #endregion private void button1_Click(object sender, System.EventArgs e) { try { //On définit l'objet connection MaConnect = SSTConnexion.GereConnexion.GetConnection(); MaCmdSelect = new SqlCommand("LireMedecin", MaConnect); MaCmdSelect.CommandType = System.Data.CommandType.StoredProcedure; MonDataAdapter = new SqlDataAdapter(MaCmdSelect); //On remlpli le dataset MonDataAdapter.Fill(ds,"Liste_Medecin"); //on affecte le dataset au datagrid dataGrid1.DataSource = ds.Tables["Liste_Medecin"]; } catch(Exception xcp) { MessageBox.Show(xcp.Message); } } } }