Sinon quelqu'un peut me dire s'il ferait pareil que moi / ou si je fais une erreur :
Par exemple : j'ai une table Livre avec 2 colonnes : IdentLivre (numéro unique) + TitreLivre, ce qui me donne :
Remplissage :
Ajout d'un nouvel item + sélection de celui-ci :Code:
1
2
3
4
5
6
7
8
9
10
11
12 DataSet oDS = new DataSet(); DbProviderFactory dbpf = DbProviderFactories.GetFactory("System.Data.SqlClient"); DbDataAdapter oDa; oDa = dbpf.CreateDataAdapter(); oDa.SelectCommand = _ConnexionSQL.oConnexionMaBase.CreateCommand(); oDa.SelectCommand.CommandText = "select IdentLivre, TitreLivre FROM Livre order by TitreLivre"; oDa.Fill(oDS, "Livre"); this.ComboBox.DataSource = oDS.Tables["Livre"]; this.ComboBox.DisplayMember = "TitreLivre"; this.ComboBox.ValueMember = "IdentLivre";
En espérant ne rien oublier....Code:
1
2
3
4
5
6 DataRow oDataRow = oDataSet.Tables["Livre"].NewRow(); oDataRow["IdentLivre"] = cIdentNveaiLivre; oDataRow["TitreLivre"] = cTitreNveauLivre; oDataSet.Tables["Livre"].Rows.Add(oDataRow); this.ComboBox.SelectedValue = cIdentNveauLivre;