Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intristic Grid Control 2

Status
Not open for further replies.

AMakovoz

MIS
Jun 20, 2000
19
US
Whenever I programically change RecordSource propertity of VFP Grid Control all my initial setting for the control are gone. I need to be able to show different tables of the exact same structure based on the user's choice. What should I do?
 
Hi AMakovoz<br>&nbsp;Exactly what settings are you refering to?<br><br>Jon
 
Hi guys<br>Maybe AMakovoz is refering to the settings on the grid's Columns particularly the ControlSource property. Everytime you update the RecordSource property of the grid, the information in the RecordSource of the columns is reset or erased. <br>This is also a problem of mine but maybe other guys here know how to work around this problem
 
I remember seeing something like this.&nbsp;&nbsp;I will look it up but until then I think the answer may have been to set the recordsource to &quot;&quot; first before to the new source.&nbsp;&nbsp; <p>John Durbin<br><a href=mailto: > </a><br><a href= > </a><br>ICQ VFP ActiveList #73897253
 
Thank you, guys! To answer Jon's question, I am referring to Column width, Column and header fonts, etc properties. One solution could be to save and later restore all set at design time properties but there are too many of them and I am looking for a simpler solution.<br>Thanks again, Albert
 
Here's my two cents:<br><br>Instead of changing the recordsource for the grid, why not repopulate the recordsource table with the new data?<br><br>Example:<br>In the Form Load: && store off original table<br>USE OriginalTable && recordsource for grid<br>COPY TO TempTable (handle any indexes as well)<br><br>When the user makes a new selection:<br>SELECT OriginalTable && recourdsource table<br>ZAP (hopefully it's opened exclusively)<br>APPEND FROM NewTable FOR ! DELETED()<br>THISFORM.GRID.REFRESH()<br><br>In Form Unload:<br>ERASE OriginalTable.dbf<br>RENAME TempTable.dbf OriginalTable.dbf<br><br>This is totally theoretical and untested. But maybe it will spawn a viable solution for you.<br><br>Jon
 
Thank you, Jon. I tried this approach before, doesn't work. It looks that any manipulations with the original table effect the initial property settings and the grid look garbled. Any other ideas? Albert
 
I believe I am right.&nbsp;&nbsp;You didn't try it did you?&nbsp;&nbsp;LMK<br> <p>John Durbin<br><a href=mailto: > </a><br><a href= > </a><br>ICQ VFP ActiveList #73897253
 
Hi Albert,<br>&nbsp;&nbsp;I have tried to duplicate the behavior you are speaking of, but have been unsuccessful. I can programmatically change the recordsource of a grid and the columns (width,header fonts & captions) are not affected.<br>&nbsp;&nbsp;I tested this with two tables consisting of the same structure. I modified the columns,headers all at design time. After the grid instantiated with the original table, I opened a new table and set the recordsource to that table. It worked fine with the grid's recordsourcetype set to table or alias.<br>&nbsp;&nbsp;If this is a subclass, the problem may lie somewhere in your hierarchy.<br>&nbsp;&nbsp;Sorry I couldnt help more.<br><br>Jon
 
Hi Albert.<br>Jon's solution would work very well if your only concern is the RecordSource property of the columns. But since you mentioned layouts are also involved, I think you are also re-updating some layout properties of the grid. Like for example, everytime you touch the FontSize property of the grid, the Width property of all columns are reset.
 
What version of VFP are you using?&nbsp;&nbsp;Any Service Pack? <p>John Durbin<br><a href=mailto: > </a><br><a href= > </a><br>ICQ VFP ActiveList #73897253
 
You might try this.&nbsp;&nbsp;It solved a similar problem for me.<br><br>In the grid's INIT method:<br>Create a &quot;empty&quot; table or cursor with the structure you desire but NO DATA.&nbsp;&nbsp;Then point the grid RecordSource to that empty table. <br><br>Create the data table/cursor you want to display and set the RecordSource to that table. When you are done with that data table (before you change anything else) set the RecordSource back to the empty table.&nbsp;&nbsp;Create another table/cursor set the RecordSource value...etc.<br>
 
Save the column properties in arrays, one array for each property you want to save, before you change the recordsource.&nbsp;&nbsp;Then after you change, reset the grid column properties from these arrays like this:<br><br>lnCount=thisform.mygrid.columncount<br>PRIVATE acColumnWidth[lnCount]<br>FOR i=1 to lnCount<br>&nbsp;&nbsp;&nbsp;&nbsp;acColumnWidth<i>=thisform.mygrid.columns<i>.Width<br>NEXT<br>thisform.mygrid.recordsource=&quot;newtable&quot;<br>FOR i=1 to lnCount<br>&nbsp;&nbsp;&nbsp;&nbsp;thisform.mygrid.columns<i>.Width = acColumnWidth<i><br>NEXT<br><br>Here I just saved the column widths, but you can do that for all the properties that get reset by the recordsource change.<br>
 
Err, there are supposed to be brackets in some lines in my previous message, I'll change them to parentheses instead:<br><br>lnCount=thisform.mygrid.columncount<br>PRIVATE acColumnWidth(lnCount)<br>FOR i=1 to lnCount<br>&nbsp;&nbsp;&nbsp;&nbsp;acColumnWidth(i)=thisform.mygrid.columns(i).Width<br>NEXT<br>thisform.mygrid.recordsource=&quot;newtable&quot;<br>FOR i=1 to lnCount<br>&nbsp;&nbsp;&nbsp;&nbsp;thisform.mygrid.columns(i).Width = acColumnWidth(i)<br>NEXT<br><br><br>
 
This is long, but it might be what your looking for.
I programmatically set my grid upon startup.&nbsp;&nbsp;This allows me to change column orders, or anything after I've already been running.&nbsp;&nbsp;The following is my function that sets the column and then, some example lines on using it.

Function SetColumn
lParameters c_Field,nWide,cHeader,nCount,cTipText
local cCom,cCom2,cCom3

&nbsp;&nbsp;&nbsp;***&gt;Note: abandoned cTipText.... can't do what I want
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;cCom3 = '&quot;'+upper(alltrim(c_Field))+'&quot;'
&nbsp;&nbsp;&nbsp;if nWide &lt; len(alltrim(cHeader))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nWide = len(alltrim(cHeader))
&nbsp;&nbsp;&nbsp;endif
&nbsp;&nbsp;&nbsp;nWide = nWide+1
&nbsp;&nbsp;&nbsp;*****&gt;Execute setup on column
&nbsp;&nbsp;&nbsp;cCom = &quot;Thisform.Grid1.Column&quot;+alltrim(str(nCount))+;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;.ControlSource&quot;
&nbsp;&nbsp;&nbsp;&cCom = &cCom3

&nbsp;&nbsp;&nbsp;cCom = &quot;Thisform.Grid1.Column&quot;+alltrim(str(nCount))+;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;.Header1.Caption&quot;
&nbsp;&nbsp;&nbsp;&cCom = cHeader

&nbsp;&nbsp;&nbsp;cCom = &quot;Thisform.Grid1.Column&quot;+alltrim(str(nCount))+;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;.Width&quot;
&nbsp;&nbsp;&nbsp;cCom2 = cCom
&nbsp;&nbsp;&nbsp;&cCom = (nWide*fontmetric(6,&quot;ARIAL&quot;,9,&quot;B&quot;))

&nbsp;&nbsp;&nbsp;cCom = &quot;Thisform.Grid1.Column&quot;+alltrim(str(nCount))+;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;.Text1.Width&quot;
&nbsp;&nbsp;&nbsp;&cCom = &cCom2


&nbsp;&nbsp;&nbsp;cCom = &quot;Thisform.Grid1.Column&quot;+alltrim(str(nCount))+;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;.Readonly&quot;
&nbsp;&nbsp;&nbsp;&cCom = .t.

&nbsp;&nbsp;&nbsp;cCom = &quot;Thisform.Grid1.Column&quot;+alltrim(str(nCount))+;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;.SelectOnEntry&quot;
&nbsp;&nbsp;&nbsp;&cCom = .t.

******
Thisform.Grid1.ColumnCount = 12
nkount = 0
***&gt;Column
&nbsp;&nbsp;&nbsp;nkount = nkount+1
&nbsp;&nbsp;&nbsp;cField = &quot;ContactName&quot;
&nbsp;&nbsp;&nbsp;Thisform.SetColumn(alias()+&quot;.&quot;+cField,fSize(cField)-4,&quot;Name&quot;,nkount,&quot;&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fieldname&nbsp;&nbsp;,&nbsp;&nbsp;&nbsp;size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;,&nbsp;&nbsp;header,column#
***&gt;Column
&nbsp;&nbsp;&nbsp;nkount = nkount+1
&nbsp;&nbsp;&nbsp;cField = &quot;Contacttitle&quot;
&nbsp;&nbsp;&nbsp;Thisform.SetColumn(alias()+&quot;.&quot;+cField,fSize(cField)-5,&quot;Title&quot;,nkount,&quot;&quot;)

***&gt;Column
&nbsp;&nbsp;&nbsp;nkount = nkount+1
&nbsp;&nbsp;&nbsp;cField = &quot;PluginName&quot;
&nbsp;&nbsp;&nbsp;Thisform.SetColumn(alias()+&quot;.&quot;+cField,fSize(cField)-5,&quot;Plug In&quot;,nkount,&quot;&quot;)

***&gt;Column
&nbsp;&nbsp;&nbsp;nkount = nkount+1
&nbsp;&nbsp;&nbsp;cField = &quot;Addr1&quot;
&nbsp;&nbsp;&nbsp;Thisform.SetColumn(alias()+&quot;.&quot;+cField,fSize(cField)-5,&quot;Address 1&quot;,nkount,&quot;&quot;)
 
I had just such a problem.&nbsp;&nbsp;I created a class that outputs properties to txt file. It's simple to implement...&nbsp;&nbsp;I've posted at another web site...<br><br><A HREF=" TARGET="_new"> called inicode.prg<br><br>I'm not sure if I can post programs here or not (I'm new).<br><br> <p> <br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>
 
Thank you all! Actually, it was my problem: somewhere along the program code I was closing the file and even though I was re-opening it later it apparently screw the grid. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top