Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid - CursorAdapter
Message
From
30/11/2005 17:30:57
 
 
To
30/11/2005 15:06:07
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01073232
Message ID:
01073499
Views:
20
Hi!

Thanks for the code it will help a lot. I can maybe extend this to handle my needs as well.

I am surprised that it dosen't work like the views worked with grids when calling the views requery with parameters. I thought that maybe CursorFill() would create a new underlying temp dbf but surely not CursorRefresh() but I guess I was wrong. This makes working with grids and cursoradapters not as easy as it should have been.

Thanks again.

Sarosh

>Hey Sarosh,
>
>I had the same problem. Here is some code that fixed it for me. However, if you start having custom controls (combobox, etc.) in the grid columns then it gets a bit more complicated. I've just avoided putting any custom controls in the columns (which I never really liked anyways).
>
>Put the following code into your grid base class in two custom methods [SaveGridAttributes and RestoreGridAttributes]. Just call oGrid.SaveGridAttributes() before refreshing the cursor and call oGrid.ResotreGridAttributes() after refreshing the cursor.
>
>*Note that you need to also create a custom property of the grid named oGridAddtribute for this to work.
>
>Code to save the grid's attributes [SaveGridAttributes()]:
>
>LOCAL lcColumnName as String
>LOCAL loColumnControlSource as Collection, ;
>	  loColumnWidth as Collection, ;
>	  loGridAttribute as Collection, ;
>	  loColumnHeader as Collection
>LOCAL loColumn as Column
>
>STORE [] TO lcColumnName
>STORE NULL TO loColumnControlSource,loColumnWidth,loGridAttribute,loColumn,loColumnHeader
>
>loColumnWidth=CREATEOBJECT([Collection])
>loColumnControlSource=CREATEOBJECT([Collection])
>loColumnHeader=CREATEOBJECT([Collection])
>loGridAttribute=CREATEOBJECT([Collection])
>
>FOR EACH loColumn IN This.Columns
>	lcColumnName = ALLTRIM(UPPER(loColumn.Name))
>	loColumnControlSource.Add(loColumn.ControlSource,lcColumnName)
>	loColumnWidth.Add(loColumn.Width,lcColumnName)
>	loColumnHeader.Add(loColumn.Header1.Caption,lcColumnName)
>ENDFOR
>loGridAttribute.Add(This.RecordSourceType,[RECORDSOURCETYPE])
>loGridAttribute.Add(This.RecordSource,[RECORDSOURCE])
>loGridAttribute.Add(This.ColumnCount,[COLUMNCOUNT])
>loGridAttribute.Add(loColumnControlSource,[COLUMNCONTROLSOURCE])
>loGridAttribute.Add(loColumnWidth,[COLUMNWIDTH])
>loGridAttribute.Add(loColumnHeader,[COLUMNHEADER])
>
>STORE loGridAttribute TO This.oGridAttribute
>
>
>Code to restore the grid's attributes [RestoreGridAttributes()]:
>
>LOCAL lcColumnControlSource as String, lcColumnName as String, lcColumnHeader as String
>LOCAL lnColumn as Integer, lnColumnWidth as Integer
>LOCAL loColumnWidth as Collection, ;
>	  loColumnControlSource as Collection, ;
>  	  loColumnHeader as Collection, ;
>	  loGridAttribute as Collection
>LOCAL loColumn as Column
>
>STORE [] TO lcColumnControlSource, lcColumnName, lcColumnHeader
>STORE 0 TO lnColumn, lnColumnWidth
>STORE NULL TO loColumnWidth, loColumnControlSource, loColumnHeader, loGridAttribute, loColumn
>
>IF !ISNULL(This.oGridAttribute)
>	loGridAttribute=This.oGridAttribute
>	loColumnWidth=This.oGridAttribute([COLUMNWIDTH])
>	loColumnControlSource=This.oGridAttribute([COLUMNCONTROLSOURCE])
>	loColumnHeader=This.oGridAttribute([COLUMNHEADER])
>
>	This.RecordSourceType=loGridAttribute.Item([RECORDSOURCETYPE])
>	This.RecordSource=loGridAttribute.Item([RECORDSOURCE])
>	This.ColumnCount=loGridAttribute.Item([COLUMNCOUNT])
>
>	FOR lnColumn = 1 TO This.ColumnCount
>		loColumn = This.Columns(lnColumn)
>		lcColumnName = ALLTRIM(UPPER(loColumn.Name))
>
>		lcColumnControlSource = loColumnControlSource.Item(lcColumnName)
>		loColumn.ControlSource=lcColumnControlSource
>		
>		lcColumnHeader = loColumnHeader.Item(lcColumnName)
>		loColumn.Header1.Caption = lcColumnHeader
>		
>		lnColumnWidth = loColumnWidth.Item(lcColumnName)
>		loColumn.Width = lnColumnWidth
>	ENDFOR
>	This.Refresh()
>	This.SetFocus()
>ENDIF
>
>>Hi!
>>
>>I have a form with two grids on it grdCustomer (Parent) and grdOrders (Child) and the grid's RecordSources are a cursors created by cursoradapters in the dataenvironment of the form.
>>
>>In the grdCustomer's AfterRowColChange Event I have tried calling the cursoradapter's CursorRefresh() and CursorFill() -ThisForm.DataEnvironment.cadOrders.CursorRefresh()/CursorFill() methods and the grid looses all its column settings because a new underlying cursor gets created each time I call CursorRefresh() or CursorFill().
>>
>>Other than saving the grids columns settings (I would not like to do this as there are many columns and many currentcontrols in columns - very complicated dynamic expressions etc.) and then restoring them after calling CursorRefresh() or CursorFill() is there any other way?
>>
>>Thanks.
>>
>>Sarosh
Previous
Reply
Map
View

Click here to load this message in the networking platform