Avatar of Millkind
Millkind
Flag 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

Visual Basic.NET

Avatar of undefined
Last Comment
Ivo Stoykov

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ivo Stoykov

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23