Link to home
Start Free TrialLog in
Avatar of FMabey
FMabeyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I would think that setting the filter for every cell is excessive.  You would want to attach to the RowEnter instead.
Avatar of FMabey

ASKER

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.
What value is Nothing (I have no way to tell from here)?
Avatar of FMabey

ASKER

DGV_Structure.CurrentRow.Index).Cells("RFIStr").Value
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America 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
Avatar of FMabey

ASKER

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!
Avatar of FMabey

ASKER

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!
Avatar of FMabey

ASKER

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.