DataGridView Sort Issue

Posted by justinfowler on 26-Apr-2010 08:33

Hi,

10.2B using a Microsoft DataGridView control with a proBindingSource.

When the user clicks a column I want to sort the query, so on the proBindingSource 'SortRequest' event I fire the method that re-opens the query. Doing this causes the DataGridView to go 'nuts'. Flashes, sometimes crashes the session. Basically it seems the datagrid is stuck in a loop of some sort.

Any ideas? Code that reproduces the issue is attached.

Thanks,

Justin

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/dataGridIssue.zip:550:0]

All Replies

Posted by Peter Judge on 26-Apr-2010 08:36

When the user clicks a column I want to sort the query, so on the

proBindingSource 'SortRequest' event I fire the method that re-opens

the query.

What does this method do?

[update: these ar ethe kinds of replies one makes when (a)  it's Monday morning and (b) one replies via email. I just realised you attached the code]

-- peter

Posted by justinfowler on 26-Apr-2010 08:42

Hi Peter,

The relevant stuff are these 2 methods. popDataGrid prepares the query and attaches it to the pbs. bs1_SortRequest assigns a var that determines the sort order then runs popDataGrid. In my actual application I have code that runs popDataGrid many times based on clicks in a treeview without issue, so I'm not sure running it multiple times is the issue...

class:

    DEF PRIVATE VAR qttTest AS HANDLE NO-UNDO.

    DEF PRIVATE VAR vttTestCurrSort AS CHAR NO-UNDO INIT "ttTest.f1".

/* snip */

    METHOD PRIVATE VOID popDataGrid ():

        DEF VAR vQuery AS CHAR NO-UNDO.

        IF VALID-HANDLE (qttTest) THEN qttTest:QUERY-CLOSE ().       

        ELSE CREATE QUERY qttTest.

        qttTest:SET-BUFFERS(BUFFER ttTest:HANDLE).

        ASSIGN vQuery = "FOR EACH ttTest no-lock"

               vQuery = vQuery + " BY " + vttTestCurrSort.

        qttTest:QUERY-PREPARE (vQuery).

        qttTest:QUERY-OPEN().

        bs1:HANDLE = qttTest.

    END METHOD.

@VisualDesigner.

METHOD PRIVATE VOID bs1_SortRequest( INPUT sender AS System.Object, INPUT args AS Progress.Data.SortRequestEventArgs ):

     ASSIGN vttTestCurrSort = "ttTest." + args:FieldName.

        IF NOT args:ASCENDING THEN

            ASSIGN vttTestCurrSort = vttTestCurrSort + " DESCENDING".

        THIS-OBJECT:popDataGrid().

     RETURN.

END METHOD.

end class...

Posted by Peter Judge on 26-Apr-2010 08:59

Interesting. I'd report it to Tech Support .

-- peter

Posted by Håvard Danielsen on 27-Apr-2010 09:51

Note that one would not normally create a new query and bind each time a query is resorted/reopened.
If you only resort the query on the sort event the grid should behave as expected. The code below has separated the query prepare and open from your popDataGrid into a separate openQuery method that is called from the event handler.  

@VisualDesigner.
METHOD PRIVATE VOID bs1_SortRequest(INPUT sender AS System.Object, INPUT args AS Progress.Data.SortRequestEventArgs ):
    ASSIGN vttTestCurrSort = "ttTest." + args:FieldName.
    IF NOT args:ASCENDING THEN
        ASSIGN vttTestCurrSort = vttTestCurrSort + " DESCENDING".
    THIS-OBJECT:openQuery().
    RETURN.
END METHOD.

METHOD PRIVATE VOID popDataGrid ():
    IF VALID-HANDLE (qttTest) THEN qttTest:QUERY-CLOSE ().       
    ELSE CREATE QUERY qttTest.
    qttTest:SET-BUFFERS(BUFFER ttTest:HANDLE).
    THIS-OBJECT:openQuery().
    bs1:HANDLE = qttTest.
END METHOD.

method private void openQuery ():
    DEF VAR vQuery AS CHAR NO-UNDO.

    ASSIGN vQuery = "FOR EACH ttTest no-lock"
           vQuery = vQuery + " BY " + vttTestCurrSort.

    qttTest:QUERY-PREPARE (vQuery).
    qttTest:QUERY-OPEN().
end method.

This doesn't change the fact that the behavior you encountered is weird and should be reported to Support.

Posted by justinfowler on 27-Apr-2010 11:13

Thank you so much for your suggestion! With a little tweaking, I was able to make it work.

However, I was not creating a new query every time. It seems the actual issue was with the query-close() and the re-binding of the query to the prodatasource.

Regardless, it is weird behaviour. I have reported the bug.

Justin

Posted by justinfowler on 28-Apr-2010 13:24

OK an update on the issue. Tech support got back to me and suggested pretty much the same work around as you did.

They did not log it as a bug because they cannot catch what is taking place.

So don't do what I did!

Justin

Posted by Admin on 28-Apr-2010 13:31

Tech support got back to me and suggested pretty much the same work around as you did.

They did not log it as a bug because they cannot catch what is taking place.

 

Maybe Peter or Harvard could help their colleagues to catch the issue...?

Posted by Peter Judge on 28-Apr-2010 14:06

OK an update on the issue. Tech support got back to me and suggested

pretty much the same work around as you did.

They did not log it as a bug because they cannot catch what is taking

place.

Did you get a WR number?

-- peter

Posted by justinfowler on 28-Apr-2010 14:13

W/R: W004270061

Justin

This thread is closed