DataGridView 改變行列顏色


[一籃飯特稀原創,轉載請注明出自http://www.cnblogs.com/wanghafan/p/3227351.html]
1
private void ChangBackColor() 2 { 3 if (dataGridView1.Rows.Count > 0) 4 { 5 foreach (DataGridViewRow row in dataGridView1.Rows) 6 { 7 if (row.Cells["列名"].Value.ToString() == "條件") 8 { 9 row.Cells["列名"].Style.ForeColor = System.Drawing.Color.Red; 10 row.DefaultCellStyle.ForeColor = Color.Red; //改變整行的 11 } 12 } 13 DataGridViewCellStyle dgvcs = new DataGridViewCellStyle(); 14 dgvcs.BackColor = Color.Green; 15 dataGridView1.Columns["列名"].DefaultCellStyle = dgvcs; //整列 16 } 17 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM