les couleurs de mon datagridview sont codés dans le form_load
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprivate static DataTable GetStats() { //Initialisation de notre dataTable afin d'inverser DataTable table = new DataTable(); table.TableName = "stats"; table.Columns.Add("Chiffres d'Affaires", typeof(string)); table.Columns.Add("Prix Moyen Produit", typeof(string)); table.Columns.Add("Prix Moyen Commande", typeof(string)); table.Columns.Add("CA Moyen / Jour", typeof(string)); table.Columns.Add("CA / Mois", typeof(string)); table.Columns.Add("Nombres de Commandes", typeof(string)); // modifier cette ligne pour qu'elle se base sur mon fichier xml, au lieu d'utiliser un timer table.Rows.Add(new object[] { "295092.46", "16.08", "36.77", "957.47", "23936.63", "651" }); table.AcceptChanges(); return table; table.AcceptChanges(); return table; }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 1) { var dgc = dataGridView1.Rows[1].Cells[1]; dgc.Style.BackColor = Color.Aqua; } else { var dgc2 = dataGridView2.Rows[1].Cells[1]; dgc2.Style.BackColor = Color.Red; } }
namespace widget { public partial class Form1 : Form { DataSet ds = null; DataTable dt = null; public Form1() { InitializeComponent(); // retourne l'histogramme CreerGraphique(zedGraphControl1); } private void Form1_Load(object sender, EventArgs e) { string filePath = "http://www.beautefrance.com:8080/script/widget_statsvente.php"; XmlTextReader txtReader = new XmlTextReader(filePath); statsdataset.Clear(); statsdataset.ReadXml(txtReader); dataGridView1.DataSource = statsdataset; dataGridView1.DataMember = "stat"; // retourne le style lors du click sur le bouton de la page 1 this.dataGridViewStatStyle(); // retourne la methode d'affichage vertical ds = new DataSet(); dt = new DataTable(); dt = GetStats(); ds.Tables.Add(dt); DataView my_DataView = ds.Tables[0].DefaultView; this.dataGridView1.DataSource = my_DataView; DataSet new_ds = FlipDataSet(ds); my_DataView = new_ds.Tables[0].DefaultView; this.dataGridView1.DataSource = my_DataView; // on enleve le focus de selection this.dataGridView1.Rows[0].Selected = false; // style des colonnes du tableau dataGridView1.Columns[0].DefaultCellStyle.Font = new Font(Control.DefaultFont, FontStyle.Bold); dataGridView1.Columns[1].DefaultCellStyle.Font = new Font(Control.DefaultFont, FontStyle.Italic); dataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Wheat; dataGridView1.Columns[1].DefaultCellStyle.BackColor = Color.LightGray; // redimensionnement des colonnes par rapport a la largeur du widget dataGridView1.Columns[0].Width = 160; dataGridView1.Columns[1].Width = 80; }
private static DataTable GetStats() { // modifier cette ligne. Récupérer les valeurs xml (dynamiques) directement plutot que de mettre des valeurs // bidons comme ci-dessous, et ensuite utiliser un timer. table.Rows.Add(new object[] { "295092.46", "16.08", "36.77", "957.47", "23936.63", "651" }); table.AcceptChanges(); return table; }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 1) { var dgc = dataGridView1.Rows[1].Cells[1]; dgc.Style.BackColor = Color.Aqua; } else { var dgc2 = dataGridView2.Rows[1].Cells[1]; dgc2.Style.BackColor = Color.Red; } }
DataView my_DataView = ds.Tables[0].DefaultView; this.dataGridView1.DataSource = my_DataView; DataSet new_ds = FlipDataSet(ds); my_DataView = new_ds.Tables[0].DefaultView; this.dataGridView1.DataSource = my_DataView;
table.Rows.Add(new object[] { "295092.46", "16.08", "36.77", "957.47", "23936.63", "651" }); // ceci est faut, je désire un code qui récupère les données xml en direct table.AcceptChanges(); return table;
comparer Chiffres d'Affaires et CA Moyen / Jour, j'en vois pas l'intéret.
//declaration des libelles private List<String> libelles = new List<string>(); //chargement des libellés un peu au hasard libelles.Add("Chiffres d'Affaires"); libelles.Add("Prix Moyen Produit"); libelles.Add("Prix Moyen Commande"); libelles.Add("CA Moyen / Jour"); libelles.Add("CA Moyen / Mois"); libelles.Add("Nombres de Commandes"); libelles.Add("1"); libelles.Add("2"); libelles.Add("3"); libelles.Add("4"); libelles.Add("7"); libelles.Add("5"); libelles.Add("6"); // Modification de la lecture du fichier xml foreach (var item in xRoot.Descendants("stat").Descendants()) { if (item.Name.LocalName.StartsWith("ca_") && item.Name.LocalName != "ca_prec" && item.Name.LocalName != "ca_mois" && item.Name.LocalName != "ca_moyenne_jour") { ................................ Déja fais ................................... } else { dicoStat.Add(libelles[i], item.Value); i++; } //chargement de la datagridview // un peu de linq dataGridView1.AutoGenerateColumns = true ; dataGridView1.DataSource =(from kv in dicoStat from libelle in libelles where libelle == kv.Key select new { libelle, kv.Value }).ToArray(); //bonus (j'étais parti sur une autre piste //un peu de lambda si tu veux t'amuser dataStatPoco d2 = new dataStatPoco(); d2.CA xRoot.Descendants("stat").Descendants().Where(x> x.Name == "ca").Select(x=>x.Value).FirstOrDefault();