2017-01-19 31 views
0

我有一張發票中的項目的gridview。我實施了一個代碼,在網格外的文本框中接收條形碼號碼。現在,如果掃描的項目是新的,它將被添加到網格視圖中。但是,如果它已經存在,程序會將項目數量增加1。Devexpress gridview從網格視圖外部修改時更改行背景顏色

問:如何突出顯示(或着色)受影響的行(數量增加一行)?

+0

你有一些代碼來分享,讓我們知道如何在網格和文本框的外觀喜歡?你試過什麼? – kloarubeek

回答

0

DevExpress爲其GridView提供RowStyleRowCellStyle事件。

在每個事件中,都可以檢查當前樣式的行或單元格的狀態,並根據行內的數據更改其外觀。

您可以在保留跟蹤LastChanged行的表中添加隱藏的bool字段。在掃描新的條形碼之前,您可以將所有行的此字段設置爲false,並僅將其數量更改的行設置爲true。

然後,你可以使用下面的事件處理程序的一個樣式基於數據的行或單元格:

private void gridView_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) 
{ 
    if (e.RowHandle < 0) return; 

    GridView view = sender as GridView; 

    DataRowView rowView = (DataRowView) view.GetRow(e.RowHandle); 

    if ((bool)rowView["LastChanged"]) 
     e.Appearance.BackColor = Color.Yellow; 
    else 
     e.Appearance.BackColor = Color.White; 
} 

或者,如果你只是想着色量的細胞。

private void gridView_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) 
{ 
    if (e.RowHandle < 0) return; 

    if (e.Column.Name != "Amount") return; 

    DataRowView rowView = (DataRowView)(((GridView)sender).GetRow(e.RowHandle)); 

    if ((bool)rowView["LastChanged"]) 
     e.Appearance.BackColor = Color.Yellow; 
    else 
     e.Appearance.BackColor = Color.White; 
} 
0

可以使用的DataRowState屬性或您將有另一科拉姆QuantityChanged布爾,你會使用RowCellStyle事件

private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) { 
    GridView view = sender as GridView; 
    qChanged = Convert.ToBoolean(view.GetRowCellDisplayText(e.RowHandle, View.Columns["QuantityChanged "])); 
if (qChanged == true) 
e.Appearance.BackColor = Color.Red; 
}