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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Box in Grid Illegal Value

Status
Not open for further replies.

gaelin

Technical User
Jan 13, 2004
35
0
0
US
I have form that has two grids and in each I have inserted a checkbox. The check boxs expect an integer to be returned. The first grid displays without a problem, the second (when I change year) returns: Error with Column12-CurrentControl: Expression evaluated to an illegal value. I get the error on this line of code:

THISFORM.Mypageframe1.Page1.grdcust2.Column12.CURRENTCONTROL = 'chkImage'

The data is extracted from SQL Server with the same cursor name. The formats are slight differnt, the second cursor one less field, but in both cases the field the checkbox is tied to is numeric field. (Field 13 for the first cursor, field 12 for the second cursor). I have tried using a controlsource to identify each field on the grid and set the init of checkbox value to zero with same results.

I finally tested using a different cursor name for the second grid, that worked! Why? I delete the first cursor with this code USE IN (SELECT('custs')) and manually verified it does not exist before I create the second cursor.

I can use a unique cursor name for the second but it's used extensively in the module and I hoped to avoid that.
 
The thing is, that message does not necessarily mean that the checkbox returned an illegal value. It's the value of CurrentControl that is illegal. Note that's the value, not the data type, that's the problem.

So, for example, you would see that message if the column does not contain a control named chkImage. Are you sure that name is correct, and that the column (and its contained controls) actually exist at the point?

One explanation would be that, at some point, the cursor that populates the grid got destroyed, and the grid therefore lost its columns. If that's so, the solution is to set the RecordSource to an empty string just before you (re-)create the cursor, and then set it back to the cursor name.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
A ceckbox cannot display all integer values, just 0,1 and 2. Are you sure your data source has only those values?

But are you saying you're using the same cursor name in two grids? Then you could only display the same data in both grids. A cursorname is mainly not the file name of a temp file, but the name of a workarea, and those must be unique, you can't have two cursors with the same name in the same datasession.

Also, if you bind a grid to a cursor, never recreate the cursor. The moment you close a cursor, the grid will fail. Instead you can empty a readwrite cursor via ZAP and refill it with new data via insert-sql or append from a secondary query result cursor.

Bye, Olaf.
 
I did check that each cursor had the required field and was the correct data type. I saved each cursor to a table and compared the fields. Each contains a field named "custimage". Each was filled with a zero (no image of the customer document) or a higher integer (document key assigned by SQL Server) to indicate it exists. I also did set the RecordSource to a blank string before calling the stored procedure a second time for the new cursor and that had no effect. It was interesting whether I started with the second cursor and went to the first or first to second I got the same message.

As you might have noticed this grid is inside of the pageframe. I suspect there is no answer...somehow VFP holds onto the format of the first cursor. Tomorrow I will try putting the fields in the same physical location (now the fields are 12th and 13th respectively).

Thanks for your help.
 
Olaf,

I responded to Mike that the data source is 0 or a higher integer. I have used this construction for years, if the field is greater than zero, the box is checked. I do want to use the same cursor name, but your comment I can empty the original cursor and refill is interesting...I will experiment tomorrow.

 
> I do want to use the same cursor name

It's still not clear what you want. Two cursors with the same name? That's not possible.

I said you can refill a cursor with new data, if that's needed, without closing it, this is solving the problem you may have because you close the grid cursor with USE IN (SELECT('custs')). At this moment, you "pull the rug" under the grid, you remove any control in the grid and the grid will reconstruct when you recreate a cursor custs with a query, in other cases the grid would even go blank.

Bye, Olaf.
 
Gaelin,

Maybe I didn't explain things very well.

This has got nothing to do with the value of the checkbox. The problem is caused by the fact that you are, at some point, destroying the cursor that populates the grid. This could happen if you use a SELECT statement to overwrite a cursor which already exists. At the moment the SELECT is executed, it destroys the existing cursor, then immediately creates a new one. It is the destruction of the existing cursor that causes the grid to lose its columns.

So at the point at which you see the error message, the grid doesn't contain any columns, and therefore doesn't have control named chkImage, and therefore gives an "illegal value" error.

You can verify this diagnosis by suspending the program at the point of the error. In the debugger, go to the Watch window, and invoke an object reference to the form., Drill down into the form, then into the grid. You will see that it contains no columns (or anything else).

The following article explains the problem in a little more detail:
However, you don't need to adopt any of the solutions suggested in the article. Simpley set the RecordSource to a blank string before you destroy the cursor, and set it back to the cursor name after you re-create the cursor.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike/Olaf
Thanks for your help. I have the two grids running thought I'm not quite certain why both work now. I thought I had previously set the recordsource to a blank string, regenerating the cursor and then resetting the recordsource (and it did not work yesterday). I started again to ensure some code was was not deleting the cursor and it works as you told me it would.
 
The recoprdsource = "" solution only is halfways good. The grid can also lose it's added controls in that scenario. You're really safe under all circumstances with the ZAP/append approach or a view cursor you Requery(), as these two scenarios don't unbind the grid and don't close the cursor.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top