简体   繁体   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#?

i already can move rows up and down but i need to make it move up & down auto if the the value of the up row are the same of the down row and if that all row are the same value it change the color i tried hard and searching a lot but didn't find the solution please help me. 我已经可以上下移动行了,但是如果上行行的值与下行行的值相同,并且如果所有行的值都相同,那么我会使其自动上下行,它会更改颜色并进行了大量搜索,但未找到解决方案,请帮助我。

i used the below codes for move up & down 我使用以下代码上下移动

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

i have column name "Category" i need to see if it the same in the down row move the row down and check again if the same move down and so on and if it can't move it change the row color 我有列名“ Category”,我需要查看它是否在向下的一行中将其向下移动,并再次检查是否相同的向下移动等等,如果它不能移动,则更改行颜色

this code that i try to use but its not work 我尝试使用的此代码,但无法正常工作

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

To change the color of a row, subscribe to the event RowCellStyle of the Grid View. 要更改行的颜色,请订阅Grid View的事件RowCellStyle。

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

More info here . 更多信息在这里

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

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