DataGridViewCellStyle MonStyle = new DataGridViewCellStyle(dataGridView2.Rows[1].DefaultCellStyle);//je recupère un styles existant MonStyle.BackColor = Color.Red;// je le modifie comme je veux MonStyle.ForeColor = Color.White; MonStyle.SelectionBackColor = Color.Salmon; dataGridView2.Rows[2].DefaultCellStyle = MonStyle;//je l'applique à ma ligne
foreach (DataGridViewRow row in dataGridView2.Rows) { DataGridViewCell Cellule = row.Cells["Genre"]; if (Cellule.Value == null) return; if (Cellule.Value.ToString() == "Homme") Cellule.Style.ForeColor = Color.Blue; else Cellule.Style.ForeColor = Color.Purple; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionstring genre = ""; DataGridViewCellStyle MonStyle = new DataGridViewCellStyle(dataGridView2.Columns[4].DefaultCellStyle); foreach (DataRow row in cb.monDataTable1.Rows) { genre = row["Genre"].ToString(); if (genre == "Homme") { MonStyle.ForeColor = Color.Blue; dataGridView2.Columns[4].DefaultCellStyle = MonStyle; } else { MonStyle.ForeColor = Color.Purple; dataGridView2.Columns[4].DefaultCellStyle = MonStyle; } }
genre = row["Genre"].ToString();qui doit te retrouner "je suis une cellule"
row.Cells[1].Value.ToString();
row.Cells[1].Value.ToString();
foreach (DataGridViewRow row in dataGridView2.Rows) { DataGridViewCellStyle MonStyle = new DataGridViewCellStyle(dataGridView2.Columns[0].DefaultCellStyle); DataGridViewCell Cellule = row.Cells["Genre"]; if (Cellule.Value == null) return; if (Cellule.Value.ToString() == "Homme") { MonStyle.ForeColor = Color.Blue; Cellule.Style = MonStyle; } else { MonStyle.ForeColor = Color.Purple; Cellule.Style = MonStyle; } }