leGrid.DataSource = (DataTable)dtResultat; leGrid.DataBind(); // ici le grid se rempli tout seul
private System.Windows.Forms.DataGridView _grid; private System.Windows.Forms.ComboBox _cbo; private void PopulateDataGridView() { _grid.Rows.Clear(); // la valeur en cours de la combo string sValCombo = _cbo.SelectedItem.ToString(); if( !String.IsNullOrEmpty(sValCombo) ) { // requete avec sValCombo // Bind grid } } private void _cbo_SelectedIndexChanged(object sender, EventArgs e) { // Vide et rerempli le grid Cursor.Current = Cursors.WaitCursor; try { PopulateDataGridView(); } catch ( Exception ) { } finally { Cursor.Current = Cursors.Default; //_grid.Focus(); } }
private void combo_salarié_SelectedIndexChanged(object sender, EventArgs e) { string ComboSala; int k = 0; ComboSala = combo_salarié.SelectedItem.ToString(); connexion.Open(); SqlDataAdapter command new SqlDataAdapter("SELECT * FROM dbo.T_Temporaire where Temp_Salarie '" + ComboSala + "' ", connexion); command.Fill(data_temporaire2, "Temp_Periode"); command.Fill(data_temporaire2, "Temp_Service"); command.Fill(data_temporaire2, "Temp_Salarie"); command.Fill(data_temporaire2, "Temp_CodeProjet"); command.Fill(data_temporaire2, "Temp_LibProjet"); command.Fill(data_temporaire2, "Temp_NbJours"); command.Fill(data_temporaire2, "Temp_Commentaires"); //Dgv_D_Salarie.DataSource = data_temporaire.Tables[0]; foreach (DataRow row in data_temporaire2.Tables[0].Rows) { if (k < data_temporaire2.Tables[0].Rows.Count) { Dgv_D_Salarie.Rows[j].Cells[1].Value = row["Temp_Periode"]; Dgv_D_Salarie.Rows[j].Cells[3].Value = row["Temp_Service"]; Dgv_D_Salarie.Rows[j].Cells[4].Value = row["Temp_CodeProjet"]; Dgv_D_Salarie.Rows[j].Cells[5].Value = row["Temp_LibProjet"]; Dgv_D_Salarie.Rows[j].Cells[6].Value = row["Temp_NbJours"]; Dgv_D_Salarie.Rows[j].Cells[7].Value = row["Temp_Commentaires"]; } j++; } connexion.Close(); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question