Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Data type mismatch with Checkbox in grid
Message
From
27/05/2003 03:11:38
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
26/05/2003 21:43:18
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00792917
Message ID:
00792963
Views:
25
>Others have posted threads on here describing 'data type mismatch' when there is a checkbox in a grid. However, I think that most of the threads pertained to checkboxes in grids where the grid was defined at design time. I am building a grid programmatically. Now matter what I did, I would either get data type mismatch when I either a) clicked on the checkbox at runtime, or b) set the bound property to .t. for the column that the checkbox was in -programmatically - while building the grid.
>
>For some inexplicable reason, the only way I got this to work was to first assign a numeric global variable as the control source to the column, while building the grid - then, after assigning the recordsource, reassigning the control source to my cursor's numeric field. Even though: a) my checkbox class has a 0 as the default and b) my cursor has a numeric value for the field that will be bound to the checkbox, I still get this data type mismatch problem. Inspecting the checkbox object in the debugger shows that it has a type of 'N'.
>
>I'm glad it's working, but I feel as if the code is so fragile, because I really don't understand why. Can anyone shed some light? Here is a fragment of the code:

Snip...

David,
There is nothing wrong there for it to error out. As I could see you start with a recordsource (a grid snaps to an alias even if you don't set one). Any columns added would get the next available field from recordsource, if all fields are used then starts to use from field number one again.
At this point you've columns (or you add them) and they've controlsources. When you try to add a checkbox, current column.controlsource should either be a logical or numeric. If not data type mismatch occurs. Using bound=.f. is not the way to go IMHO.

I think if your code were organized like this it might work :

lnobjcntr=lnobjcntr+1
*This.grdtaggedlist.&lccolobjname..Bound=.F.

this.grdtaggedlist.&lccolobjname..controlsource='curtaggedlist.ltagged'

*this.grdtaggedlist.&lccolobjname..controlsource=gnnumber
this.grdtaggedlist.&lccolobjname..newobject('Checkbox1','chkboxtag','satfilter')
....

Some other notes about your code :
lcsqlnone= ' and (1 = 1) '
Why is this ? Isn't it same as saying :
lcsqlnone= ' and .t. '
Reminded me my Prolog coding days :)
If this is not VFP3 why do you need it ? Use 'nofilter' clause.

Does initial grid has some columns ? Instead of adding columns with addobject :
If no initial column :
with This.grdtaggedlist
 .RecordSource = ''
 .Columncount = -1
*....
 .Recordsource = 'whatever'
endwith

* If has initial columns :
with This.grdtaggedlist
 .RecordSource = ''
*....
 .Recordsource = 'whatever'
endwith
with This.grdtaggedlist
 .RecordSource = ''
 .Columncount = -1 && Do this first to clear out
 .ColumnCount = reccount('Curerptaggedlists_d')+1 && +1 is checkbox column?
 scan
  with .Columns(recno('Curerptaggedlists_d'))
     .ControlSource=Alltrim(Curerptaggedlists_d.ccontrolso)
     .Width=Curerptaggedlists_d.nwidth
     .header1.Caption=Alltrim(Curerptaggedlists_d.cheader)
  endwith
 endscan
 with .Columns(.Columncount)
   .controlsource='curtaggedlist.ltagged'
   .newobject('Checkbox1','chkboxtag','satfilter')
   .checkbox1.caption=''
   .currentcontrol="checkbox1"	
   .sparse=.f.		
   .visible=.t.	
   .width=Curerptaggedlists_d.nwidth && ??? Isn't this 0 now
   .header1.caption='Selected'	
   .bound=.t.		
 endwith
 .recordsource='Curtaggedlist'
endwith
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform