vb.netcomponentone

Copy data from C1FlexGrid to C1FlexGrid


I'm using a C1FlexGrid, which version I'm not entirely sure. I am trying to copy rows that are selected in FlexGridA to FlexGridB, and so far I'm unable to locate anything online to help, and all of the functionality that I've tried to use so far (such as add) does not work.

How can I accomplish this?

I HAVE to use C1FlexGrids, so if the answer is for a regular MSFlexGrid it won't work. I've already tried using some solutions for those and they don't work either.

EDIT:

I now have information copying between tables, but it's copying the entirety of what the table has after it's filtered, not just the selected rows.

There are two flexgrids. On form1 is fgResults, on form2 is fgDelete. I want to copy the selected rows from fgResults to fgDelete so that a user can see what they've selected to delete from the database before just blindly clicking and deleting something they don't want to.

Here is what I have to copy the data:

            AddFilterRow(MultiDelete.fgDelete)
            Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream
            fgResults.WriteXml(MS)
            MS.Position = 0
            MultiDelete.fgDelete.ReadXml(MS)

The issue is, again, it's adding EVERYTHING that was filtered, not just the selected rows.


Solution

  • So after several hours of digging, I found a workaround as there doesn't appear to be a direct way to copy one row from a C1FlexGrid to another.

                Dim DT As New DataTable
    
                For c = fgResults.Cols.Fixed To fgResults.Cols.Count - 1
                    DT.Columns.Add(fgResults.Cols(c).Name, fgResults.Cols(c).DataType)
                Next
    
                For r = fgResults.Rows.Fixed To fgResults.Rows.Count - 1
                    If fgResults.Rows(r).Selected Then
                        Dim row As DataRow = DT.NewRow()
                        For c = fgResults.Cols.Fixed To fgResults.Cols.Count - 1
                            If fgResults(r, c) Is Nothing Then
                                If fgResults.Cols(c).DataType.FullName = "System.DateTime" Then
                                    row.Item(c - fgResults.Cols.Fixed) = Date.MinValue
                                ElseIf fgResults.Cols(c).DataType.FullName = "System.Double" Then
                                    row.Item(c - fgResults.Cols.Fixed) = 0
                                Else
                                    row.Item(c - fgResults.Cols.Fixed) = ""
                                End If
    
                            Else
                                row.Item(c - fgResults.Cols.Fixed) = fgResults(r, c)
                            End If
                        Next
                        DT.Rows.Add(row)
                    End If
                Next
    

    What I'm doing here is creating a new datatable, adding all rows to it that are selected, and then I fill the second grid with the created datatable. If anyone has a more direct way of doing this I am all ears, but this works for now for what I'm trying to accomplish.