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!

how do i use a grid to select one or more rows 1

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi Everyone,
This is is what i would like to accomplish:
1- display the records in a grid
2- be able to select the records/rows i want in that grid
3- print those selected rows in a report
Can i have some clues, tips on # 2, i know i can select the records in a browse and mark them for deletion and then just
"report form whatever for deleted to printer" but since i am still in the process of learning, would like to know if possible a better and more sophisticate way to do it.
Thanks in advance
Ernesto
 
First, you need to understand that a grid does not contain data. It's simply a display device put over a table, cursor, or view (which are essentially the same thing).

The way to do it is to select the data you want displayed by the grid into a view or read-write cursor that has an additional Logical field. Display that field in the grid. The user simply clicks it to select that field.

Craig Berntson
MCSD, Visual C# MVP,
 
One option would be to add a logical field to the underlying cursor or table (the one that you use to populate the grid). Then add a column to the grid; add a checkbox to that column, bound to the logical field.

The user can then select (or deselect) a row by ticking (or un-ticking) the checkbox. That will have the effect of toggling the logical field.

You can then print your report in the usual way, but add a FOR clause to the REPORT FORM command, so that only records where the local field is .T. get printed.

To make the grid look better, use the DynamicBackColor property to highlight the rows where the checkbox is ticked. This will make it more obvious which rows are selected.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi MikeLewis,
That is exactly what i did with the table, i added a logical field named "prt", i will try to add a CHECK BOX to that column, will need to find out how ?
But i just want to thank you for the guide
Again thanks a lot
Ernesto
 
To add a checkbox to a grid column, right click on the grid, select edit from the menu
then click in the column (not the header) to get that column selecetd in the properties window.

Now click on the toolbar item for a check box, and then back in the grid.

You need to set the columns property to not be read only and change the sparse setting to false.

Just two more things to do:

1) get rid of the current control (probably a text box) by selecting it in the
properties window and then clicking in the column again and hitting the delete key.

2) clear the 'caption' for the checkbox.

I usually change the background colour as well (for any non read only fields)



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
i will try to add a CHECK BOX to that column

Griff has told you the process to add a CheckBox to the Grid.

One thing that I do in addition to that visually helps the users is to utilize each Grid Column's DynamicBackColor property.
I use it to change the color of the individual cell's background color for those Row's where a condition exists

An example of that might be:
Code:
* --- If Selected = TRUE, display as [COLOR=#FCE94F]YELLOW[/color] background ---
* --- If Selected = TRUE, leave as WHITE background ---
IIF(!Selected,RGB(255,255,0),RGB(255,255,255))

This has no functional benefit, but it does assist the user in dramatically seeing the Selected rows.

Note - this code would need to be put into Each and Every Grid Column DynamicBackColor property that you would want affected.

Good Luck,
JRB-Bldr





 
Hi Guys, after i did what Mike and Griff told me, in fact i did something wrong cause when the grid display the record and i go to put a check mark in the Check box i got this error.

"Error with Check1 Value: data type mismatch", i make the field this is bound to the check1 a logical field, i am in vfp 5.0 anyway, do i need to define the default value for the check mark and write a code for when the check box get checked ?
Thanks
 
Not come across that error, check boxes bound to database fields should be any kind of problem.

No code is 'required' although you could maintain a count using the interactive change of the check box.

Is the COLUMN bound to the logical field, or the check box only?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Grif ,
I got it, for some reason, the field bound changed to another field, so now is fine, i was trying to put the code "JRB-Bldr" posted in each column, Grid Column DynamicBackColor property as IIF(!Selected,RGB(255,255,0),RGB(255,255,255)) but that does not work for me, all i want is if a user put a check mark in that row, i want that the whole row to change the color, is that possible ?
Thanks
 
IIF(!Selected,RGB(255,255,0),RGB(255,255,255))

Keep in mind that I did not know the name of your Logical Grid Checkbox (Include) field so in my example I used one named: Selected

If your Logical Grid CheckBox field is named something else, change the code accordingly.

Good Luck,
JRB-Bldr
 
jrbbldr,
Yes i know i replaced the IIF(!Selected,RGB(255,255,0),RGB(255,255,255)) by IIF(!closejob.prt,RGB(255,255,0),RGB(255,255,255))
and what i did is just put this IFF in " Column1 DynamicBackColor property" and when i put a check mark in the the check box that is actually my last column in the grid that column cells does not chamge it's color, what i am doing wrong ?
Thanks a lot


 
Ernesto,

Are you sure you are putting the IIF(...) in quotes? You need something like this:

Code:
THISFORM.Grid1.Column1.DynamicBackColor = "IIF(!Selected,RGB(255,255,0),RGB(255,255,255))"

Note the quotes around the bit after the equals. (That's assuming you are setting the property in code, rather than in the properties window.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You can put the DynamicBackColor in as Mike has suggested or you can compose the IIF() expression and then go to the Form's Property Window, navigate to the desired Form - Grid - Column - DynamicBackColor property and then merely Paste it in 'as is' with no Quotes around it.

Upon execution I have found that immediately after putting the check into the Grid Column's Checkbox, the color does NOT change.

But once you move off the record, the DynamicBackColor appears as intended.

Since a multi-record action is generally initiated with some Form Control other than the Grid itself (maybe a Button, Non-Grid Checkbox, etc.), this poses no problem because once you set Focus on something other than the Grid itself, the DynamicBackColor is shown as intended.

Good Luck,
JRB-Bldr






 
Mike and JRB-Bld
I put this, IIF(!closejob.prt,RGB(255,255,0),RGB(255,255,255)) no quites in the DynamicBackColor property column1 of the grid , also my column8 wich is the last column of the grid is where i have the check box check1, also in this column DynamicBackColor property i have the same code IIF(!closejob.prt,RGB(255,255,0),RGB(255,255,255)), i only want this in those columns, now when i run the form the column8 background is painted green inmmediatly where the check box is, when i check the check box with the mouse and leave that record/row and go to another record the cell under the column1 it is not painted, obviously something i got wrong, i don't know, maybe i explained myself beter now than before and that is why you were assuming i was correct, please let me know
Thanks to both
Ernesto
 
If you looked in the VFP HELP system for IIF() you would see something like IIF(<condition> , <if condition TRUE> , <if condition FALSE>)

Obviously the way you have written your DynamicBackColor expression equates to:
Code:
  IF NOT closejob.prt
       Set BackColor to RGB(255,255,0) --> Green
  IF closejob.prt
       Set BackColor to RGB(255,255,255) --> White

So if your Grid's Control table initially has closejob.prt FALSE then you will immediately get a Green BackColor on those columns.

Good Luck,
JRB-Bldr


 
JRB-Bldr,
Thanks for clarifying, i realized with your explanation that if it is not true i should keep it white and then if true then green, it is working now thanks a lot to you and the rest
Ernesto
 
Ok Guys,
Another question, if i want to affect the whole record/row when i click i check the check box what property should be implemented ?
in other words, want to do is when i tick the check box, i want all the columns in that row to change to the same color as the column 8, where can i globally made that change ?
Thanks again
Ernesto
 
You have to apply the dynamicbackcolor to every column, there is no central property for the whole row.
You can easily do that by a loop, eg in Grid.Init:

Code:
FOR EACH loColumn in This.Columns
   loColumn.DynamicBackColor = ...
ENDFOR

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top