troubleshooting Question

How to copy a filtered datagridview results into a dataset

Avatar of Millkind
MillkindFlag for Afghanistan asked on
Visual Basic.NET
1 Comment1 Solution270 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Ivo Stoykov

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros