|
|
|
DataGridView ต้องการเพิ่มสีใน Cell ที่มีค่ามากกว่าที่กำหนด Win App C# |
|
|
|
|
|
|
|
ทำได้ละครับ
|
|
|
|
|
Date :
2011-09-02 20:58:00 |
By :
SPIRITT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้แล้วโพสไว้ด้วยครับ
|
|
|
|
|
Date :
2011-09-02 21:11:23 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
int b = Convert.ToInt32(ReseAmount); // ReseAmount = 200000
SqlConnection db = new SqlConnection(conn);
try {
db.Open();
string sql;
sql = "SELECT ";
sql += "Resu_Send_Total ";
sql += "FROM ";
sql += "T_Results ";
sql += "WHERE ";
sql += "Rese_ID = '" + RequestID + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, db);
DataSet ds = new DataSet();
da.Fill(ds, "Cust");
if (ds.Tables[0].Rows.Count > 0) {
int i;
for (i = 0; i < dst.Tables[0].Rows.Count; i++) {
if (Convert.ToInt32(dataGridView1.Rows[i].Cells["Resu_Send_Total"].Value) < b) {
dataGridView1.Rows[i].Cells["Resu_Send_Total"].Style.BackColor = Color.Pink;
}
else if (Convert.ToInt32(dataGridView1.Rows[i].Cells["Resu_Send_Total"].Value) > b) {
dataGridView1.Rows[i].Cells["Resu_Send_Total"].Style.BackColor = Color.Red;
}
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
finally {
db.Close();
}
|
|
|
|
|
Date :
2011-09-02 21:17:38 |
By :
SPIRITT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เยี่ยมครับ
|
|
|
|
|
Date :
2011-09-03 10:06:39 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณน่ะค่ะ สำหรับแนวทางโค้ด
ปรับนิดหน่อยก้อใช้ได้แล้ว
|
|
|
|
|
Date :
2012-10-12 12:29:35 |
By :
kik |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวอย่างอีกแบบค่ะ อันนี้เป็นกำหนดสีเองใช้รหัส RGBค่ะ
Code (C#)
private void dgvCashAdv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
int iRow = e.RowIndex;
DataGridViewRow r = dgvCashAdv.Rows[iRow];
string cellValue = r.Cells[10].Value.ToString(); //UnitPrice
if (cellValue == "ส่งค่าแล้ว")
{
r.DefaultCellStyle.BackColor = Color.FromArgb(255, 204, 255);
r.DefaultCellStyle.ForeColor = Color.FromArgb(185, 10, 173);
}
else
{
r.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 153);
r.DefaultCellStyle.ForeColor = Color.FromArgb(255, 26, 26);
}
}
|
|
|
|
|
Date :
2012-10-16 10:15:16 |
By :
rassarin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|