dBASE Programming - Edit Grid with rowselect=ture

This is Interesting: Free IT Magazines  
Home > Archive > dBASE Programming > May 2005 > Edit Grid with rowselect=ture





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Edit Grid with rowselect=ture
Big Al

2005-05-19, 5:50 pm

After many years of 5.7 I'm just coming to grips with 2.5 and grids and love the rowselect feature highlighting the whole row, but it appears to disable editing. My customers scroll down the list of songs and hit the spacebar to choose one which changes
the WANT value to .t., works fine without the rowselect on and have tried various forms of this . .

function GRIDALLSONGS_onGotFocus
ON KEY LABEL Spacebar Check
return

function Check
IF this.rowset.fields["want"].value = true
this.rowset.fields["want"].value = false
ELSE
this.rowset.fields["want"].value = true
ENDIF
return

but can't get it to work, what am I doing wrong ?? Is there a better way ?

Ken Mayer [dBVIPS]

2005-05-19, 5:50 pm

Big Al wrote:
> After many years of 5.7 I'm just coming to grips with 2.5 and grids
> and love the rowselect feature highlighting the whole row, but it
> appears to disable editing. My customers scroll down the list of
> songs and hit the spacebar to choose one which changes the WANT value
> to .t., works fine without the rowselect on and have tried various
> forms of this . .
>


This is working as designed. You will want to add code to turn off
rowSelect, or even better, don't allow editing in the grid. For the most
part, you have less control over any editing/control in the grid when
the user edits data there. It is considered to be better to use the grid
to display the data, and edit in "normal" controls ...

Ken



--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase
rb

2005-05-20, 7:49 am

Hi,
To add to what ken said.
Is your row editable.
I see you don't have a begin append()
or a save()
Perhaps the changes are not being made because they are not allowed to be
made throu code.

Robert

"Big Al" <bigal@thekaraokeshop.co.nz> wrote in message
news:LAwULNMXFHA.1760@news-server...
> After many years of 5.7 I'm just coming to grips with 2.5 and grids and

love the rowselect feature highlighting the whole row, but it appears to
disable editing. My customers scroll down the list of songs and hit the
spacebar to choose one which changes the WANT value to .t., works fine
without the rowselect on and have tried various forms of this . .
>
> function GRIDALLSONGS_onGotFocus
> ON KEY LABEL Spacebar Check
> return
>
> function Check
> IF this.rowset.fields["want"].value = true
> this.rowset.fields["want"].value = false
> ELSE
> this.rowset.fields["want"].value = true
> ENDIF
> return
>
> but can't get it to work, what am I doing wrong ?? Is there a better way ?
>



Jan Hoelterling

2005-05-21, 2:51 am

Hi Big Al <g>,

what you want to do in this instance is to make the grid editable, but set a
frozencolumn to a checkbox field ("want"). That way, the cursor is confined
to the field with the checkbox and the user can use the space bar to toggle
the "want" value. No other value in the grid is editable.

Don't forget to disable append & delete in the grid...

Since you already have a field in the table, you can easily use that.
However, if the application is multi-user, this approach obviously won't
work because any update to "want" would apply to all users. In this
instance, you can add a calculated field to the rowset. It's a little more
tricky, let me know if you need this and I'll post some sample code later.

Hope this helps,

Jan


Big Al

2005-05-23, 5:53 pm

Jan Hoelterling Wrote:

> Hi Big Al <g>,
>
> what you want to do in this instance is to make the grid editable, but set a
> frozencolumn to a checkbox field ("want"). That way, the cursor is confined
> to the field with the checkbox and the user can use the space bar to toggle
> the "want" value. No other value in the grid is editable.
>
> Don't forget to disable append & delete in the grid...
>
> Since you already have a field in the table, you can easily use that.
> However, if the application is multi-user, this approach obviously won't
> work because any update to "want" would apply to all users. In this
> instance, you can add a calculated field to the rowset. It's a little more
> tricky, let me know if you need this and I'll post some sample code later.
>
> Hope this helps,
>
> Jan
>
>

Thanks Jan, luckily it is not multi muser. I know I can do it as you suggested but I'd like to try and do it with rowselect=true because it is easier for the user to see which record they're on.

I've played more with my programme:

function GRIDALLSONGS_onGotFocus
ON KEY LABEL Spacebar Check
return

function Check
IF this.rowset.fields["want"].value = true
this.rowset.fields["want"].value = false
ELSE
this.rowset.fields["want"].value = true
ENDIF
return

From what Ken and rb said it should work but I'm obviously doing (or not doing) something very stupid (not understanding OOD?).

If I put the Function Check before the endclass the ON KEY goes looking for a programme. If I put it after the endclass or in a programme it tells me "Variable Undefined: this ". So how do I get ON KEY LABEL Spacebar to do its thing ??
Roland Wingerter

2005-05-24, 5:57 pm

Big Al wrote:
> After many years of 5.7 I'm just coming to grips with 2.5 and grids
> and love the rowselect feature highlighting the whole row, but it
> appears to disable editing. My customers scroll down the list of
> songs and hit the spacebar to choose one which changes the WANT value
> to .t., works fine without the rowselect on and have tried various
> forms of this . .
> [...]
> but can't get it to work, what am I doing wrong ?? Is there a better
> way ?

-------
First, as Robert points out, you forgot rowset.save().

Second, mixing OODML and the xdml command ON KEY is a bit tricky.
See comments in the form below.

Roland


// ****************************************
********//
// How to change logical field value with spacebar
// when Grid.rowselect = true
// ****************************************
********//
set database to
if not file("myfile.dbf")
create table myfile(;
field1 boolean, field2 char(10), field3 char(10),field4 char(10))
use myfile
generate 20
Endif
use
** END HEADER -- do not remove this line
//
// Generated on 24.05.2005
//
parameter bModal
local f
f = new gridRowselectEditForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class gridRowselectEditForm of FORM
with (this)
height = 11.7727
left = 10.5714
top = 1.1364
width = 70.7143
text = "Change logical field value with spacebar"
endwith

this.MYFILE1 = new QUERY()
this.MYFILE1.parent = this
with (this.MYFILE1)
left = 2.2857
top = 1.2727
sql = 'select * from "myfile.DBF"'
active = true
endwith

this.GRID1 = new GRID(this)
with (this.GRID1)
onGotFocus = class::GRID1_ONGOTFOCUS
onLostFocus = class::GRID1_ONLOSTFOCUS
dataLink = form.myfile1.rowset
columns["COLUMN1"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN1"].dataLink = form.myfile1.rowset.fields["field1"]
columns["COLUMN1"].editorType = 2 // CheckBox
columns["COLUMN1"].width = 14.2857
columns["COLUMN2"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN2"].dataLink = form.myfile1.rowset.fields["field2"]
columns["COLUMN2"].editorType = 1 // EntryField
columns["COLUMN2"].width = 14.2857
columns["COLUMN3"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN3"].dataLink = form.myfile1.rowset.fields["field3"]
columns["COLUMN3"].editorType = 1 // EntryField
columns["COLUMN3"].width = 14.2857
columns["COLUMN4"] = new GRIDCOLUMN(form.GRID1)
columns["COLUMN4"].dataLink = form.myfile1.rowset.fields["field4"]
columns["COLUMN4"].editorType = 1 // EntryField
columns["COLUMN4"].width = 14.2857
with (columns["COLUMN1"].headingControl)
value = "field1"
endwith

with (columns["COLUMN2"].headingControl)
value = "field2"
endwith

with (columns["COLUMN3"].headingControl)
value = "field3"
endwith

with (columns["COLUMN4"].headingControl)
value = "field4"
endwith

bgColor = "white"
cellHeight = 0.8
rowSelect = true
speedTip = "Change logical value with spacebar"
height = 7.3636
left = 4.1429
top = 3.7273
width = 61.8571
endwith

this.rowset = this.myfile1.rowset

function GRID1_onGotFocus
// Create reference to form
// which will be used in external function
_app.Testform = this.parent

// Call external function
ON KEY LABEL Spacebar do toggleValue
// or
// ON KEY LABEL Spacebar toggleValue()

// This leads to a syntax error,
// beacause ON KEY does not understand OOP syntax
// ON KEY LABEL Spacebar class::toggleValue()
return

function GRID1_onLostFocus
// clean up
_app.testForm = NULL
ON KEY
return

function toggleValue
// We cannot call this method with ON KEY command
? "Call to class method"
return

endclass

function toggleValue
// ? "Call to external method"

// Via the _app reference, the external function
// has access to the form's objects.
if type("_app.Testform") = "O"
_app.Testform.rowset.fields["field1"].value = ;
not _app.Testform.rowset.fields["field1"].value
_app.Testform.rowset.save()
_app.Testform.rowset.next(0)
endif
return




Roland Wingerter

2005-05-24, 5:57 pm

Big Al wrote:
>
> If I put the Function Check before the endclass the ON KEY goes
> looking for a programme. If I put it after the endclass or in a
> programme it tells me "Variable Undefined: this ". So how do I get
> ON KEY LABEL Spacebar to do its thing ??

------
It's a bit tricky. See the sample in my other message.

Roland


Big Al

2005-05-24, 5:57 pm

> Big Al wrote:
> ------
> It's a bit tricky. See the sample in my other message.
>
> Roland
>
>

Wow, no wonder I was having trouble.

You guys are truly amazing - I'll give it a try.
Roland Wingerter

2005-05-25, 7:47 am

Big Al wrote:
> Wow, no wonder I was having trouble.
>
> You guys are truly amazing - I'll give it a try.

------
Good luck!

Roland

-----
dBKON 2005 - 4. deutschsprachige dBASE Entwickler-
und Anwenderkonferenz am 11. und 12. November 2005
Neueste Infos unter: www.dbase-konferenz.de


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com