Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grids built from cursors
Message
From
17/06/2001 10:19:29
 
 
To
16/06/2001 22:24:32
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00520315
Message ID:
00520360
Views:
21
>Brian,
>
>Well sonuvagun, that worked. I had tried this many times and many ways but with no sucess before. Is the 'csr' required
>before my cursor name? Before I said "CREATE CURSOR Pledgers" and now I changed it to "CREATE CURSOR csrPledgers".
>Was that the big difference or is there something else?
>Also, I know this is going to sound wimpy, but I don't know how to add fields to a grid without using the builder. I think that I was
>able to make it work once by doing what you suggested, created a table with the name and attributes of my cursor temporarily.
>This is a learning experience from me, I have always gone directly off of tables before and am learning about cursors at the
>suggestion of several people.
>
>Thanks so much for your help.
>
>Fred

Hi Fred,

No, the 'csr' is not required, I just feel it's good practice to use it since it quickly distinguishes to others reading the code that it isn't an actual table.
You should be able to call the cursor 'Pledgers', but without seeing your code, I'm not sure why it would have given you a problem.

You don't have to assign each field to the grid columns. If your cursor is going to have the fields in the same order you want them to appear in the grid, then there really isn't a need to go and specify the controlsource down at the column or column control level. It's easier to just assign the Grid.RecordSource="csrPledges" and the field will appear left to right in the same order.

Of course there are times when I create the grid manually in the designer because I want to see all of the formating immediately. In that case, you can set the Grid.ColumnCount = no. of columns/fields in your cursor. So if pledges has six fields, just set Grid.ColumnCount = 6 and just change the Grid.Column1.Header1.Caption = "Field Name" for each one. Yes, this can be a long process if you have a lot of fields you want to show. Which is why if you keep Grid.ColumnCount = -1, the grid will automatically show all of the fields of the Grid.RecordSource when it is assigned. You can then put all of the formatting code in a custom form method or in the grids init event...

For instance:
*** Form Init ***
SELECT * FROM pledges INTO CURSOR csrPledges ORDER BY lastname
Grid1.RecordSource = "csrPledges"
In the Grid Init (or Refresh) Event you might have:
WITH This
        .Column1.Header1.Caption = "Plegde ID"
	.Column1.Width = 10
	.Column2.Header1.Caption = "First Name"
	.Column2.Width = 30
	.Column3.Header1.Caption = "Last Name"
	.Column3.Width = 30
              *** etc. ***
        *** The SetAll lets you change properties for the colums as a whole
        *** instead of each column one-at-a-time
	.SetAll("FontSize",8,"Column")
	.SetAll("FontSize",8,"Header")
	.SetAll("SelectedBackColor",RGB(255,0,0),"Text1")
ENDWITH
Again, if you need to recreate your cursor at some point, you need to:
Grid1.RecordSource = ""
SELECT * FROM pledges INTO CURSOR csrPledges ORDER BY lastname
Grid1.RecordSource = "csrPledges"
Grid1.Refresh
So you don't lose any of the grid code or formatting you set up while in the Form Designer.


Oh, and don't worry, we all learned sometime. I learn new stuff everyday and the people here are really great about helping out.


- Brian


VFP6 SP5, VFP8 SP1, VFP 9 SP 1 and Win XP SP 3 (unless otherwise specified)


www.wulfsden.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform