Link to home
Start Free TrialLog in
Avatar of Millkind
MillkindFlag for Afghanistan

asked on

How to copy a filtered datagridview results into a dataset

I need to know how to copy the filtered results of a datagrid into a dataset.

Here is how the filtered view is created.

  Private Sub filterdatagrid(sender As Object, e As EventArgs) Handles _
       tbassetmodelnumber.TextChanged, _
        tbassetname.TextChanged, _
        tbassetserialnumber.TextChanged, _
        tbsearchbuildings.TextChanged, _
        tbsearchdistributor.TextChanged, _
        tbsearchgeneralledgername.TextChanged, _
        tbsearchgeneralledgernumber.TextChanged, _
        tbsearchlocationroom.TextChanged, _
        tbsearchmanufacturer.TextChanged, _
        tbacquistionscost.TextChanged, _
        tbacquistionecost.TextChanged, _
        dtpassetacquistionsdate.ValueChanged, _
        dtpassetacquistionedate.ValueChanged
        Try
            Dim filterstring As String = ""
            Dim needand As Boolean = False
            For Each ctrl As Control In gbfilsterassetlist.Controls
                If TypeOf ctrl Is TextBox Then
                    If ctrl.Tag.ToString.Equals("Asset Acquisition Cost") Then
                        If tbacquistionscost.Text.Length > 0 And tbacquistionecost.Text.Length > 0 Then
                            If needand Then
                                filterstring = filterstring & " and "
                            End If
                            filterstring = filterstring & "([" & ctrl.Tag & "] >= " & tbacquistionscost.Text & ") and ([" & ctrl.Tag & "] <= " & tbacquistionecost.Text & ")"
                            needand = True
                        End If
                    Else
                        If ctrl.Text.Length > 0 Then
                            If needand Then
                                filterstring = filterstring & " and "
                            End If
                            filterstring = filterstring & "([" & ctrl.Tag & "] like '*" & ctrl.Text & "*')"
                            needand = True
                        End If
                    End If
                ElseIf TypeOf ctrl Is DateTimePicker Then
                    If needand Then
                        filterstring = filterstring & " and "
                    End If
                    If dtpassetacquistionsdate.Value = Date.Today And dtpassetacquistionedate.Value = Date.Today Then
                        filterstring = filterstring & "([" & ctrl.Tag & "] >= #" & dtpassetacquistionsdate.Value & "#) and ([" & ctrl.Tag & "] <= #" & dtpassetacquistionedate.Value & "#)"
                        needand = True
                    End If
                End If
            Next ctrl
            dvgridview.RowFilter = filterstring
            dvgridview.RowStateFilter = DataViewRowState.CurrentRows
        Catch ex As Exception
            mainform.errorwrite("Fixed Assets Select Assets" & ex.ToString)
        End Try
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial