0

I have a gridview of items in an invoice. I implemented a code to receive barcode number in a text box outside the grid. Now if the scanned item is new it's added to the grid view. But if it already exists the program increases the quantity of the item by one.

Q: How can I highlight (or colorize) the affected row (the row at which the quantity increased by one) ?

Abo Haidar
  • 1
  • 1
  • 1

2 Answers2

0

DevExpress provides the RowStyle and RowCellStyle events for their GridView.

In each event, you can check the status of the currently styled row or cell, and change its appearance based on data within the row.

You could add a hidden bool field to your table that keeps track of the LastChanged rows. Before you scan a new bar code, you can just set this field to false for all rows, and set it to true only for rows which had their amount changed.

Then you could use one of the following event handlers to style the row or cell based on the data:

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;
}

Or if you only wanted to color the Amount cell.

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;
}
GantTheWanderer
  • 1,255
  • 1
  • 11
  • 19
0

You can use DataRowState property or you will have another colum QuantityChanged boolean and you will use RowCellStyle event

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;
}
kgzdev
  • 2,770
  • 2
  • 18
  • 35