現在有增刪改的按鈕,然后有一個datagrid,如何實作datagrid表中行顏色根據增刪改來變化,比如新增的資料行就用綠色,刪的就紅色,改的用黃色。
uj5u.com熱心網友回復:
可以根據數據庫某個欄位來判斷就行了啊private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
for (int i = 0; i < this.dataGridView1.Rows.Count-1; i++)
{
try
{
string colorstr = dataGridView1.Rows[i].Cells["Bit"].Value.ToString();
if (colorstr == "新增")
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Green;
}
else if (colorstr == "已刪除")
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
else if (colorstr == "修改")
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
else
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
uj5u.com熱心網友回復:
更新、新增的如果沒保存前可以這么處理,弄個標志位判斷即可,刪的都看不見了,還怎么顯示?uj5u.com熱心網友回復:
也有可能是邏輯洗掉呀uj5u.com熱心網友回復:
樓上的 WINDOWS 版的。asp.net 版本的給你個思路把,代碼不寫了。太多。
用 RowDataBind 事件 然后在里面用 獲取行資訊然后用 attribute 設定其 css backgroud-color 即可,記得是 tr 的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/133046.html
標籤:C#
上一篇:richtextbox顯示rtf格式,rtf里面有圖片,但是顯示不出來
下一篇:新人求助。。。c#小程式里的問題
