Page 1 of 1
Editing fields in a Datagrid Table
Posted: Thu Jan 14, 2010 9:32 pm
by phaworth
Couple of questions on this.
First, I want to allow editing of some columns in my datagrid but not others. I see a property to allow/disallow editing but it is at the datagrid level not the column level. I think I have to create a column template then add code to the EditValue command?
After the user has finished editing a field, I need to process the new value in the field, specifically add it to a total field on the same form as the datagrid. In the manual, there's discussion of a command named CloseFieldEditor but I don't see that in the column template, because it's stored in a button of the datagrid library I believe. Is it possible to do my processing right after the call to EditFieldText in the EditValue command of my column Template or should I copy all the default code for the column into my column template and then add the code I need in the CloseFieldEditor command?
Thanks
Pete
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 12:11 am
by trevordevore
Editing column - You correct in that you will need to customize the column behavior. Just follow the instructions for doing that in this lesson:
How Do I Override the Default Behavior For Rendering Data to a Cell?
To limit editing to some columns just modify the EditValue command. You can specify which columns can be edited using a switch statement:
Code: Select all
command EditValue
switch the dgColumn of me
case "MyColumn"
EditFieldText the long ID of me, the dgIndex of me, the dgColumn of me
break
end switch
end EditValue
Saving values - CloseFieldEditor is a message that is sent though it isn't trapped anywhere by default. You can add a CloseFieldEditor handler to your Data Grid group script or to your custom column behavior script.
You can't store your values in the EditValue command as EditFieldText only opens the editor. It does not wait until the editor has closed to continue processing.
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 12:39 am
by phaworth
Thanks Trevor, that should work just fine.
Another thing that came up since I wrote the original post. When the user double clicks to edit, I want all of the filed to be selected. I tried putting a select statement right before the call to EditFieldText in EditValue but that had no effect and I see why that wouldn't work. Can you suggest a way to do this?
Pete
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 4:48 am
by trevordevore
The preOpenFieldEditor message is sent after a field opens but before it is displayed. The target is the field so you could do this:
Code: Select all
on preOpenFieldEditor
select char 1 to -1 of me
end preOpenFieldEditor
There is also a new, yet to be documented, feature that came in 4.0 called the dgTemplateFieldEditor (well, it sort of existed prior to 4.0 but was broken). If you execute the following code prior to calling EditFieldText then the text will be selected:
Code: Select all
set the dgTemplateFieldEditor["select text"] of the dgControl of me to true
Other properties include utf8text, unicodetext, rtftext, htmltext and text. By default the field editor uses the text of the field you pass in to EditFieldText. Setting a dgTemplateFieldEditor property allows you to use one of the other properties to fill in the editor field. I often use UTF8 myself.
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 5:51 am
by phaworth
Great, thanks Trevor, I'll try both of these solutions.
Pete
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 4:14 pm
by trevordevore
So it hit me last night that I might have added a property for toggling whether or not a column is editable. It turns out I did, it just isn't in the property inspector or the docs (now added to docs).
Code: Select all
set the dgColumnIsEditable[COLUMN_NAME] of group "DataGrid" to false
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 6:32 pm
by phaworth
Thanks Trevor I'll try that. BTW, the code for selecting all the text in a field seems to be missing an "of me" unless I'm misunderstanding something.
Pete
Re: Editing fields in a Datagrid Table
Posted: Fri Jan 15, 2010 6:33 pm
by trevordevore
Yes it is. Actually you should use
as it is a property of the Data Grid. I've updated my previous post.
Re: Editing fields in a Datagrid Table
Posted: Fri Oct 29, 2010 3:58 am
by openworld
Pete and Trevor,
I'm just getting up speed with LiveCode - and very glad to find the reference to htmltext properties in datagrids in your comment below!
I'm looking for a way for a columin in a datagrid to accept htmltext.
Thanks to Bernd's help with a revBrowser solution, a prototype app that I'm preparing can now dragdrop selected htmltext into a card field.
Yet I've had no luck in getting a datagrid to accept htmltext.
Is there a script to modify the dgTemplateFieldEditor so that column 1 -- in my case, it's for a datagrid called "fClip" -- can accept the htmltext chunk that I'm trying to drop onto it?
Ideally, I'd love this dropped htmltext chunk to go into the first available (empty) row in column 1.
Appreciate any advice or examples you or others here can share on how this might be done!
Best,
Mark Frazier
@openworld
trevordevore wrote:The preOpenFieldEditor message is sent after a field opens but before it is displayed. The target is the field so you could do this:
Code: Select all
on preOpenFieldEditor
select char 1 to -1 of me
end preOpenFieldEditor
There is also a new, yet to be documented, feature that came in 4.0 called the dgTemplateFieldEditor (well, it sort of existed prior to 4.0 but was broken). If you execute the following code prior to calling EditFieldText then the text will be selected:
Code: Select all
set the dgTemplateFieldEditor["select text"] of the dgControl of me to true
Other properties include utf8text, unicodetext, rtftext, htmltext and text. By default the field editor uses the text of the field you pass in to EditFieldText. Setting a dgTemplateFieldEditor property allows you to use one of the other properties to fill in the editor field. I often use UTF8 myself.