Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Some Grid Bugs... I think
Message
From
03/01/2001 06:00:53
 
 
To
02/01/2001 19:09:07
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00458706
Message ID:
00458824
Views:
20
Hi, Mike!

I did exactly what you did here. After a lot of time spent for tuning, I finally got only one or 2 cases - combinations of grid refreshing commands that give good results. Following it my grid class method 'refreshaftersorting'. It sent as is without changes, so it contains a lot of things related to our framework. I added comments where needed. Hope you will get general idea here and get your grid to work.
lparameters poColumn
* column reference should be passed, it is used to set focus to column that was sorted. If we do
* not do this, grid will jump to the currently focused column and hide column that we just sorted
* in case when focused column is outside of visible range of grid. This makes no sense, of course, * because users usually want to see sorted column immediately to use sorting results.

* this method called internally only as event from header object after sorting.

with this && this is grid object
	.lSorting = .T. && this flag used in other methods to do not lock screen and make refreshes
                        && in afterrowcolchange events branch. Refreshes done here, so otehr 
                        && refreshes might spoil results or, at least, take some additional time
                        && slowing down grid refreshing

	local lcOldArea, lcGridAlias
	m.lcOldArea = select(0)
	
	m.lcGridAlias = this.GetGridAlias() && alias used by grid to display data. I used method
                                            && because my grid uses SQL cursor too.
	select (m.lcGridAlias)

	* store 'real' grid position, this is needed because it may change in the next part of code
	local nOldRecNo
	m.nOldRecNo = .nRecno && nRecNo contains current record number that was assigned in 
                              && AfterRowColChange event, used to highlight current row, but we
                              && can use it here as well


        * recalibrate grid. This is needed to show current row at the center of the grid. For
        * example, current row is the top row. When we sort in another order, current row is the
        * bottom row. Without calibrating only one row will be shown in grid - current row (that is
        * last now). This is even when all rows of cursor fit into the grid. Looks confusing.
        * To show it at the center of the grid, (or show all visible rows), need to move record
        * pointer somewhere far from current record, better to the top of cursor.
	* this must be <b>BEFORE any refresh of grid</b>
	if between(m.nOldRecNo,1,reccount())
		locate for .T. && go top
	ENDIF
	.Refresh()

	* activate cell that is appropriate to sorting column, so grid will not scroll out from sorting column

	&& restore row position - it may be changed during indexing and cell activation
	if !.lInit
		m.poColumn.SetFocus()
		if between(m.nOldRecNo,1,reccount())
			go (m.nOldRecNo)
		ENDIF
*		.Refresh !!! not needed here! column.SetFocus refreshes grid automatically
	else
                * if we sort grid during grid Init process, say, when restore grid layout
                * from user preferences file, SetFocus will not work.
		if between(m.nOldRecNo,1,reccount())
			go (m.nOldRecNo)
		ENDIF
		.Refresh()
	endif

	select (m.lcOldArea)
	
	DOEVENTS && this is required to draw everything for grid BEFORE any other visible changes 
                 && done, as well as move focus to column BEFORE any further changes
	.lSorting = .F. && finished sorting refresh process
endwith
>In the next code, when clicking on the header the record pointer moves here too. It moves strangly though, say you are on the second displayed item, the order will be reversed, and the record that used to be above the first item is now the selected item. If the third visible record is the current record in the grid, when the order is reversed the record two above the first record will become the current one. If you watch, the top record always stays on top, so if the top record is current, when the order is flipped it will remain current. If you're not lost by this point, isn't that wierd?
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform