【问题标题】:Devexpress gridview change row background color when modified from outside the grid view从网格视图外部修改时,Devexpress gridview 更改行背景颜色
【发布时间】:2017-01-19 21:50:11
【问题描述】:

我有发票中项目的网格视图。我实现了一个代码以在网格外的文本框中接收条形码编号。现在,如果扫描的项目是新的,它就会被添加到网格视图中。但如果它已经存在,程序会将项目的数量增加一。

问:如何突出显示(或着色)受影响的行(数量增加一的行)?

【问题讨论】:

  • 你有一些代码要分享,所以我们知道网格和文本框的样子吗?你自己尝试了什么?

标签: c# gridview devexpress devexpress-windows-ui


【解决方案1】:

DevExpress 为其GridView 提供RowStyleRowCellStyle 事件。

在每个事件中,您可以检查当前设置样式的行或单元格的状态,并根据行内的数据更改其外观。

您可以在表中添加一个隐藏的布尔字段来跟踪 LastChanged 行。在您扫描新条码之前,您可以将此字段设置为所有行的 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;
}

【讨论】:

    【解决方案2】:

    您可以使用 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 2011-04-29
      • 2016-07-17
      • 2012-03-02
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      相关资源
      最近更新 更多