繁体   English   中英

如果行单元格值相同,则上下移动行或更改行颜色。gridview devexpress winforms c#?

[英]move Rows up and down or change row color if the row cell value are the same gridview devexpress winforms c#?

我已经可以上下移动行了,但是如果上行行的值与下行行的值相同,并且如果所有行的值都相同,那么我会使其自动上下行,它会更改颜色并进行了大量搜索,但未找到解决方案,请帮助我。

我使用以下代码上下移动

    void uphaya()
    {
        DevExpress.XtraGrid.Views.Grid.GridView view = GVHaya;
        view.GridControl.Focus();
        int index = view.FocusedRowHandle;
        if (index <= 0) return;

        DataRow row1 = view.GetDataRow(index);
        DataRow row2 = view.GetDataRow(index - 1);
        object val1 = row1[OrderFieldName];
        object val2 = row2[OrderFieldName];
        row1[OrderFieldName] = val2;
        row2[OrderFieldName] = val1;

        view.FocusedRowHandle = index - 1;
    }

    void downhaya()
    {
        DevExpress.XtraGrid.Views.Grid.GridView view = GVHaya;
        view.GridControl.Focus();
        int index = view.FocusedRowHandle;
        if (index >= view.DataRowCount - 1) return;

        DataRow row1 = view.GetDataRow(index);
        DataRow row2 = view.GetDataRow(index + 1);
        object val1 = row1[OrderFieldName];
        object val2 = row2[OrderFieldName];
        row1[OrderFieldName] = val2;
        row2[OrderFieldName] = val1;

        view.FocusedRowHandle = index + 1;
    }

我有列名“ Category”,我需要查看它是否在向下的一行中将其向下移动,并再次检查是否相同的向下移动等等,如果它不能移动,则更改行颜色

我尝试使用的此代码,但无法正常工作

  for (int i = 0; i < GVHaya.RowCount; i++)
 if ((((GVHaya.GetRowCellValue(i, "Category").ToString()) == (GVHaya.GetRowCellValue(i -1, "Category").ToString())))) 
          {
              downhaya()
          }

要更改行的颜色,请订阅Grid View的事件RowCellStyle。

private void view_RowStyle(object sender, RowCellStyleEventArgs e)
{
     e.Appearance.BackColor =  Color.Red;
}

更多信息在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM