Alimentation ComboBox MVC
Bonjour voici mon problème , je dois faire une architecture en MVC sur mon programme ( C# .net WinForm , VS2019) . Je gère la plupart du logiciel mais je n'arrive pas à alimenter ma combobox en mvc.
Exemple pour une de mes listView j'ai fais ceci :
Dans mon contrôleur :
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
|
class Alimentation
{
readonly Modèle.TravellokedConnexion connexion = new Modèle.TravellokedConnexion(); // Appel de la déclaration de connexion du modèle
readonly Modèle.Modèle_Sql requery = new Modèle.Modèle_Sql(); // Appel le modèle SQL
readonly Modèle.SQL_Join @Join = new Modèle.SQL_Join(); // Appel des jointues SQL necèssaire aux requètes
public List<ListViewItem> List_Demande()
{
MySqlConnection connection = new MySqlConnection(connexion.ConnexionBDD()); // Connection avec la base de données PHP MYAdmin
List<ListViewItem> listViewDemandeItems = new List<ListViewItem>();
MySqlCommand cmdall = new MySqlCommand(requery.SelectAgent() + Join.JointurePK_FK(), connection);
connection.Open();
using (MySqlDataReader Lire = cmdall.ExecuteReader())
{
while (Lire.Read()) // Boucle While qui regarde toutes les infos que l'on souhaite voir avec la méthode "lire"
{
string Code_Conges = Lire["Code_Conges"].ToString();
string Demande = Lire["Demande"].ToString();
string Identifiant = Lire["Identifiant"].ToString();
string Debut = Lire["Debut"].ToString();
string Fin = Lire["Fin"].ToString();
string Etat = Lire["Etat"].ToString();
string Garantification = Lire["Garantification"].ToString();
//root.Root_Listview_Demande.Items.Add(new ListViewItem(new[] { Code_Conges, Demande, Identifiant, Debut, Fin, Etat, Garantification }));// Ajout des nouvelles valeurs dans la list view
listViewDemandeItems.Add(new ListViewItem(new[] { Code_Conges, Demande, Identifiant, Debut, Fin, Etat, Garantification }));
}
}
connection.Close();
return listViewDemandeItems;
} // Alimentation des ListViews de demande de congés
} |
Dans ma vue :
Code:
1 2 3 4 5 6 7 8 9
|
readonly Controlleurs.Alimentation alimentation = new Controlleurs.Alimentation();
foreach (ListViewItem item in alimentation.List_Demande())
{
ListView_Holiday_Admin.Items.Add(item);
}
ListView_Holiday_Admin.Refresh(); |
J'aimerais gerer la comobox d'une façons similaire ... si possible...
Pour l'instant j'ai tout dans la vue de cette façon :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
MySqlConnection connection = new MySqlConnection(connexion.ConnexionBDD()); /*********************************/
connection.Open(); /*********************************/
ComboBox_Holiday_Admin.DropDownStyle = ComboBoxStyle.DropDownList;
MySqlCommand command = new MySqlCommand(requery.EtatDemande(), connection); /*********************************/
MySqlDataReader reader = command.ExecuteReader(); /*********************************/
while (reader.Read())
{
ComboBox_Holiday_Admin.Items.Add(reader.GetString("Etat"));
}
connection.Close();*/ /*********************************/ |
Cependant, lorsqu'il y a " /*********************************/ " en commentaire, ce sont des lignes qui font appel aux modèles pour être valable ce qui n'est pas bon en MVC...
Merci