C1flexgrid move row up or down

Posted by: saidnai on 16 June 2021, 10:59 am EST

  • Posted 16 June 2021, 10:59 am EST

    Hi,

    I have a filled C1Flexgrid with rows from the database. If necessary the user need to move one or more rows up/down over Button (Up) or Button (Down). After the move a public variable will be set to true means move has been done.

    Thank for VB code Trial.

    Best regards

    Said

  • Posted 17 June 2021, 5:51 am EST

    Hi Said,

    Please note that moving Rows in FlexGrid is not supported in Bound Mode. If you want to move rows in bound mode, you will have to delete rows from the data table and then insert them again at a location.

    Please refer to the sample attached and modify it according to your requirements.

    Regards

    Avnish

    FlexGridMoveVB.zip

  • Posted 17 June 2021, 6:15 am EST

    Dear Avnish,

    I know what you mean with the delete.

    The planned variable that is set to true if up/down happend. calls a function that update the field (sequence:1,2,3,4,5,etc) in each record and reload the data table sorted again.

    Best regards

    Said

  • Posted 18 June 2021, 5:32 am EST

    Dear Avnish,

    I know what you mean with the delete.

    I tried your sample, it is working but it is loosing the Cursor for the moved row.

    The planned variable that is set to true if up/down happend. calls a function that update the field (sequence:1,2,3,4,5,etc) in each record and reload the data table sorted again. In this way the Up/Down can happen only the Flexgrid keeping the Cursor on the moved row and shoul not move down or up if the first/last row is a Summation.

    Best regards

    Said

  • Posted 18 June 2021, 6:21 am EST

    Hi Said,

    If you don’t want the cursor to move you can just store the value of Row and Col property of FlexGrid and then set those values back after you have moved the row.

    Private Sub UpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UpToolStripMenuItem.Click
           Dim r = C1FlexGrid1.Row
           Dim c = C1FlexGrid1.Col
    
           Dim row = C1FlexGrid1.Row - C1FlexGrid1.Rows.Fixed
           If row = 0 Then
               Return
           End If
           Dim data = dt.NewRow()
           data.ItemArray = dt.Rows(row).ItemArray.Clone()
           dt.Rows.RemoveAt(row)
           dt.Rows.InsertAt(data, row - 1)
    
           C1FlexGrid1.Row = r
           C1FlexGrid1.Col = c
       End Sub
    

    Please refer to the code given above and modify it according to your requirements. If you want to keep the cursor with the row that you moved just set the Row property to the same index at which you inserted the row + the number of fixed rows in FlexGrid.

     C1FlexGrid.Row = newIndex + C1FlexGrid.Rows.Fixed
    

    Regards.

    Avnish

  • Posted 18 June 2021, 6:40 am EST

    Dear Avnish,

    I have adjusted it as needed and it works perfectly. Any other issue in this regard i will come back to you

    Best regards

    Said

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels