sgray128 7/18/2017 1:24:40 PM

Get a dataset from a filtered grid

Sometimes we allow a grid to be filtered, and we want to report off of the filtered data. The grid might also be grouped and sorted which adds a complication. 

The code below is a template to use when you want to create a datatable from a filtered radgrid.

Private Sub RadMenuButtonItem1_Click(sender As Object, e As EventArgs) Handles RadMenuButtonItem1.Click
    Dim strError As String = ""
        'this gets an empty dataset. The blank parameter will return zero lines, but we'll
        'have the format for the datatable. We'll iterate through the grid and add lines to it
        'we're using a form level datatable
        moDT = DynData.SPs.FP_SalesQueue("", App.Database).getTable
        'iterate through the child rows collection
        For Each orow As GridViewRowInfo In RadGridView1.ChildRows
        'call the report
        Using frm As New CrystalReport("SalesQueue.rpt", moDT, moDT.Rows.Count, 0, mstrSalespersonID)
            'show the report
        End Using
    Catch ex As Exception
        ErrorHandler.globalErrorHandler(ex, strError, True)
    End Try
End Sub
Private Sub IterateChildRows(oRow As GridViewRowInfo)
        If oRow.HasChildRows Then
            For Each oRow2 As GridViewRowInfo In oRow.ChildRows
            Dim oNewRow As DataRow
            oNewRow = moDT.NewRow
            oNewRow("vchrSubdivisionName") = oRow.Cells("vchrSubdivisionName").Value
            oNewRow("vchrLotNumber") = oRow.Cells("vchrLotNumber").Value
            oNewRow("Address") = oRow.Cells("Address").Value
            oNewRow("CUSTNAME") = oRow.Cells("CUSTNAME").Value
            oNewRow("intMasterNumber") = Common.ToString2(oRow.Cells("intMasterNumber").Value)
            oNewRow("SOPNUMBE") = oRow.Cells("SOPNUMBE").Value
            oNewRow("SOPTYPE") = oRow.Cells("SOPTYPE").Value
            oNewRow("reqshipdate") = oRow.Cells("reqshipdate").Value
            oNewRow("Holds") = oRow.Cells("Holds").Value
            oNewRow("prmdate") = oRow.Cells("prmdate").Value
            oNewRow("TPOETA") = oRow.Cells("TPOETA").Value
            oNewRow("ReleasedToDispatch") = oRow.Cells("ReleasedToDispatch").Value
            oNewRow("dtOnTruck") = oRow.Cells("dtOnTruck").Value
            oNewRow("dtOnJob") = oRow.Cells("dtOnJob").Value
        End If
    Catch ex As Exception
        Throw ex
    End Try
End Sub