简体   繁体   中英

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

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.

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

More info here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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