[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

Very slow dataview filter

Hi all,

I have a combobox bound to a dataview/dataset. Under the CellEnter event of a datgridview I have the following code:

    Private Sub DGV_Structure_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV_Structure.CellEnter

        DV_ContDraw.RowFilter = ""  'Clear filter
        DV_ContDraw.RowFilter = "Cont = " & TXT_Contract.Text & " AND Str = '" & DGV_Structure.Rows(DGV_Structure.CurrentRow.Index).Cells("RFIStr").Value & "'"

        CB_DrawNo.SelectedText = ""

    End Sub

This filters the dataview that fills the combobox and therefore shows a different list depending upon which row the user selects. My issue is that this is not instant. There is a noticable delay when the user selects a row while the combobox gets filtered through the dataview.

Does anyone know why there could be such a delay and is there a better way of doing this whilst getting the same result?

I have replaced the datafilter code with the following:

        SqlConnection1.Open()

        'Run a select command on the dataadapter to filter out only the required contract and structure (Section)
        SQL_ContDraw.Parameters("@Cont").Value = "" & TXT_Contract.Text & ""
        SQL_ContDraw.Parameters("@Str").Value = "" & DGV_Structure.Rows(DGV_Structure.CurrentRow.Index).Cells("RFIStr").Value & ""
        SDA_ContDraw.SelectCommand = SQL_ContDraw
        SQL_ContDraw.ExecuteNonQuery()
        SDA_ContDraw.Fill(DS_ContDraw1) ' Fill the dataset (this is used to fill the dataview)

        SqlConnection1.Close()

Introducing Parameters into my dataadapter and this works a treat. However, I can't help but think that calling the database everytime I move a row is a bit excessive!

Cheers
0
FMabey
Asked:
FMabey
  • 5
  • 3
1 Solution
 
Bob LearnedCommented:
I would think that setting the filter for every cell is excessive.  You would want to attach to the RowEnter instead.
0
 
FMabeyAuthor Commented:
Thank for your reply. Agreed, but I've tried putting the filter on the rowenter but I get the following error:

Object reference not set to an instance of an object.
0
 
Bob LearnedCommented:
What value is Nothing (I have no way to tell from here)?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
FMabeyAuthor Commented:
DGV_Structure.CurrentRow.Index).Cells("RFIStr").Value
0
 
Bob LearnedCommented:
Would that be "CurrentRow"?

Try using the e.RowIndex from the event arguments instead:


    Private Sub MeasurementGrid_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MeasurementGrid.RowEnter
        Dim value As String = Me.MeasurementGrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
    End Sub

Open in new window

0
 
FMabeyAuthor Commented:
I've not abandoned this question... I've just been moved onto another project for a bit. I'll get back to this shortly and post my findings! Thanks for your patience!
0
 
FMabeyAuthor Commented:
Hi guys,

Just to say once again, this question isn't being abandoned... I'm just working on another progrect for the time being... When I get back to it I'll try out the suggestions!
0
 
FMabeyAuthor Commented:
Thanks for your patience... That works better than the cellenter. Although it's still not quite as smooth as using the parameters. However, it's not a noticable difference so I am going to go with the dataview filters due to their practicality.

Thanks again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now