PDA

View Full Version : Checkbox in ReportControl



HenryEgal
17-Jul-2009, 10:16 AM
Good morning!
Is there a way to get a checkbox in a report control column? I want to process records in a report control if the lines are checked by a user.
Thanks!

Henry

Peter Bragg
17-Jul-2009, 10:32 AM
Hello Henry,

Absolutely. One of the examples in the cSig Demo application is a sigCJReportControlDemo-SQL view and this actually has 2 checkbox columns.

Inside Procedure OnDefineColumns you should see we are calling a method "Add_Report_Column". One of the arguments tells the control whether we want a 'standard' column or a checkbox one:



Send Add_Report_Column "Meeting" 60 eRC_Integer eRC_CheckBox "CalEvent.MeetingFlag" "If(CalEvent.MeetingFlag > 0,'True','False')"


Note the eRC_Checkbox argument - this is what you need to be passing.

HenryEgal
17-Jul-2009, 10:34 AM
Peter,
Ok great! Thanks for the help.

Henry

HenryEgal
17-Jul-2009, 11:38 AM
Hello again,
Are there any samples on how to get if a column is checked or not? The user has the option to check and uncheck the columns in order to run a process.
thanks!

Ian Smith
17-Jul-2009, 03:19 PM
Hi Henry

Update in SVN.

The data for the row is now available in the string array property psData_Items. So in OnProcess_Rows / OnProcess_Rows_RowID you can get psDataItems and check the relevant item. The array is zero based.

Regards

HenryEgal
17-Jul-2009, 03:21 PM
Ian, Thanks so much! I will try this out.
Thanks!
Henry

DaveR
17-Jul-2009, 03:21 PM
I couldn't find one (but then I can't find anything nowadays :( )
The reportcontrol has a very high coolness factor but is very much a work in progress. Not only from the SIG guys but seemingly also from codejock themselves.

DaveR
17-Jul-2009, 03:27 PM
Hi Henry

Update in SVN.

The data for the row is now available in the string array property psData_Items. So in OnProcess_Rows / OnProcess_Rows_RowID you can get psDataItems and check the relevant item. The array is zero based.

Regards

Ah very good.

have you worked out how to expose the totals and subtotals functions yet?

Martin
18-Jul-2009, 06:55 AM
I would disagree very much; not in progress, this control is in use daily in lots of products and is very stable.

The one thing I do agree on is Codejock sometimes put a new feature in that do not always make sense and often seem not work how you would expect, this is the case with the totals and subtotals functions, my guess is it was put in for someone, then Codejock seemed wait and see what other developers do with it and report back to them. A classic case is in the Calendar class when they added Timelines, two versions on and it makes sense and works. We have a good working relationship with Codejock development team and they do make improvements when asked.

As for the Totals you can always do the following:


Set pbRow_Item to True

Property Number pnEstimate
Property Number pnActual

Procedure Refresh_Report
Forward Send Refresh_Report
Set pnEstimate to 0
Set pnActual to 0
End_Procedure

Procedure OnCreateRowItem Integer iColumn Handle hoItem String sValue
If (iColumn = 7) Set pnEstimate To (pnEstimate(Self) + Number(sValue))
If (iColumn = 8) Set pnActual To (pnActual(Self) + Number(sValue))
End_Procedure

Ian Smith
18-Jul-2009, 08:07 AM
Hi Dave

Please see Martins response.

We have discussed this and have decided not to include support for the SUM functions at the time. As Martin has stated we feel that the feature is not mature enough.

Also the formula are set at the item level and the report control is really a column based structure. If you have a column of subtotals and then rearrange the columns that the subtotal is based on, things break. So the class would need to be aware of the columns used in the formula and track any column moves to determine if the formula should be recoded.

DaveR
18-Jul-2009, 12:16 PM
I would disagree very much; not in progress, this control is in use daily in lots of products and is very stable.

Martin, Not knocking your excellent work so far, but I had read this thread when I first started to play with your classes
http://forum.codejock.com/forum_posts.asp?TID=11635

and it does seem the reportcontrol is very much one that the CJ developers are still refining, and not always to popular acclaim. :D scared me off, anyway....



As for the Totals you can always do the following:


Set pbRow_Item to True

Property Number pnEstimate
Property Number pnActual

Procedure Refresh_Report
Forward Send Refresh_Report
Set pnEstimate to 0
Set pnActual to 0
End_Procedure

Procedure OnCreateRowItem Integer iColumn Handle hoItem String sValue
If (iColumn = 7) Set pnEstimate To (pnEstimate(Self) + Number(sValue))
If (iColumn = 8) Set pnActual To (pnActual(Self) + Number(sValue))
End_Procedure


... and that is more elegant than what I was doing. However (and in response to Ian) it's the recalc-on-the-fly functionality that the users seem to think is relevant. :cool:.
I've the germ of an idea about this (or it might be swine flu) but I haven't tried to put it into code yet. My thought was to use a set of recids (or other line-based pointers) and matching arrays of the numbers we want to sum/subtotal/whatever. Then, whenever a column-heading is pulled onto the header bar, whatever process rebuilds the display also picks up the correct array items and calculates.

What stopped me at that point was ignorance about the class and how to make (or fake) the subtotal lines. Now I'm actually using it in a report I have the excuse to put some time into it. Now if I only had the time as well as the excuse........

HenryEgal
20-Jul-2009, 08:33 AM
Ian thanks that works great for getting all the data in each column for selected rows. That will be very useful. What I'm trying to do here is another way to select rows. The users I'm working with do not want to Click and hold control down to select a row. They want to click a checkbox in the first column. OnProcess_rows works with multi-selecting columns.
I was looking for a procedure that will go through all rows and build an array of the current values. I'm working with Procedure Process_Rows now to try and get this.
Thanks for any direction!

Henry

Ian Smith
20-Jul-2009, 11:16 AM
Hi Henry

Clunk clunk the penny drops a bit further

Try this :- add a string array property to your sub-class / object and keep track of which check boxes are ticked. You can then process this array and use the saved record IDs to find the required data.


Property String[] psSelected_Rows

Procedure DoLoad_Data
String[] sEmpty_Array

Forward Send DoLoad_Data

//Augmented to clear the array of selected rows

Set psSelected_Rows to sEmpty_Array
End_Procedure

Procedure OnComItemCheck Variant llRow Variant llItem
Boolean bChecked
Handle hoRow hoItem hoRec
Variant vRec
Integer iIndex
String sID
String[] sSelected_Rows

//Link to the Row object and get the Record object
Get phoReportRow to hoRow
Set pvComObject of hoRow to llRow
Get ComRecord of hoRow to vRec

//Link to the Record object and get the unique ID for the row
Get phoReportRecord to hoRec
Set pvComObject of hoRec to vRec
Get ComTag of hoRec to sID

//Link to the Item object and get the checked state
Get phoReportRecordItem to hoItem
Set pvComObject of hoItem to llItem
Get ComChecked of hoItem to bChecked

//Add or remove the ID from the array
Get psSelected_Rows to sSelected_Rows
If (bChecked) Begin//add it
Move sID to sSelected_Rows[(SizeOfArray(sSelected_Rows))]
End
Else Begin //Remove it
Move (SearchArray(sID, sSelected_Rows)) to iIndex
If (iIndex <> -1) Begin //should always be found
//
//Been lazy here (sorry) and used the new VDF15 function
//If not using VDF15 upgrade;) or code your own delete array
//element routine.
//
Move (RemoveFromArray(sSelected_Rows, iIndex)) to sSelected_Rows
End
End

//Save modified array
Set psSelected_Rows to sSelected_Rows
End_Procedure

HenryEgal
20-Jul-2009, 12:01 PM
Haha thanks Ian!
I'm loading loading an integer array as I load the report control. The type is eRC_db_Text so I'm building an integer array for each row in the OnPrepare_RowData. All array elements are set to zero as it is built.
I'll use the Procedure OnComItemCheck Variant llRow Variant llItem to set the element to 1 0r 0 depending on ComChecked result.
Thanks so much for all the input. Love these controls!
Thanks, Henry

chuckatkinson
21-Sep-2009, 04:28 PM
Hi Henry

Clunk clunk the penny drops a bit further

Try this :- add a string array property to your sub-class / object and keep track of which check boxes are ticked. You can then process this array and use the saved record IDs to find the required data.


Property String[] psSelected_Rows

Procedure DoLoad_Data
String[] sEmpty_Array

Forward Send DoLoad_Data

//Augmented to clear the array of selected rows

Set psSelected_Rows to sEmpty_Array
End_Procedure

Procedure OnComItemCheck Variant llRow Variant llItem
Boolean bChecked
Handle hoRow hoItem hoRec
Variant vRec
Integer iIndex
String sID
String[] sSelected_Rows

//Link to the Row object and get the Record object
Get phoReportRow to hoRow
Set pvComObject of hoRow to llRow
Get ComRecord of hoRow to vRec

//Link to the Record object and get the unique ID for the row
Get phoReportRecord to hoRec
Set pvComObject of hoRec to vRec
Get ComTag of hoRec to sID

//Link to the Item object and get the checked state
Get phoReportRecordItem to hoItem
Set pvComObject of hoItem to llItem
Get ComChecked of hoItem to bChecked

Set ComSelected of hoRow to bChecked

//Add or remove the ID from the array
Get psSelected_Rows to sSelected_Rows
If (bChecked) Begin//add it
Move sID to sSelected_Rows[(SizeOfArray(sSelected_Rows))]
End
Else Begin //Remove it
Move (SearchArray(sID, sSelected_Rows)) to iIndex
If (iIndex <> -1) Begin //should always be found
//
//Been lazy here (sorry) and used the new VDF15 function
//If not using VDF15 upgrade;) or code your own delete array
//element routine.
//
Move (RemoveFromArray(sSelected_Rows, iIndex)) to sSelected_Rows
End
End

//Save modified array
Set psSelected_Rows to sSelected_Rows
End_Procedure


Ian,

Trying to set the ComSelected of the row when the checkbox is checked (as in Red above). It works for one row, but not multiple selections and it doesn't add to the selected_rows count etc. Trying to figure out how the selection works. And if I can work row selection into the above checkbox code (just for visual effect really).

Thanks

Ian Smith
22-Sep-2009, 11:40 AM
Hi Chuck

I'll have a think about it... but if it's just a visual effect, have you thought about changing the colour of the row as the check box is checked / unchecked?

Ooops that ended up in the wrong place:eek: