Editing fields in a Datagrid Table
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Editing fields in a Datagrid Table
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
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
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Editing fields in a Datagrid Table
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:
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.
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
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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Editing fields in a Datagrid Table
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
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
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Editing fields in a Datagrid Table
The preOpenFieldEditor message is sent after a field opens but before it is displayed. The target is the field so you could do this:
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:
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.
Code: Select all
on preOpenFieldEditor
select char 1 to -1 of me
end preOpenFieldEditor
Code: Select all
set the dgTemplateFieldEditor["select text"] of the dgControl of me to true
Last edited by trevordevore on Fri Jan 15, 2010 6:34 pm, edited 1 time in total.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Editing fields in a Datagrid Table
Great, thanks Trevor, I'll try both of these solutions.
Pete
Pete
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Editing fields in a Datagrid Table
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
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Editing fields in a Datagrid Table
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
Pete
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Editing fields in a Datagrid Table
Yes it is. Actually you should use as it is a property of the Data Grid. I've updated my previous post.
Code: Select all
of the dgControl of me
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Editing fields in a Datagrid Table
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
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:
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
on preOpenFieldEditor select char 1 to -1 of me end preOpenFieldEditor
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.Code: Select all
set the dgTemplateFieldEditor["select text"] of the dgControl of me to true