User input in datagrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
User input in datagrid
Hi,
I'm building an app with datagrid. Colum 1 is "projectName", column 2 is "initialBudget", columns 3 is "expensesAsOfToday", column 4 is "amountRemaining", the latter is computed. Therefore I want the user to be able to modify or add data in columns 1 to 3 but not 4.
The question is "how do I let the user access the datagrid"? I'm thinking of changing dynamically the "Allow Text Editing" property but how can I know which cell the user is trying to edit? and BTW how do I access that property?
Or should I use another strategy?
I'm building an app with datagrid. Colum 1 is "projectName", column 2 is "initialBudget", columns 3 is "expensesAsOfToday", column 4 is "amountRemaining", the latter is computed. Therefore I want the user to be able to modify or add data in columns 1 to 3 but not 4.
The question is "how do I let the user access the datagrid"? I'm thinking of changing dynamically the "Allow Text Editing" property but how can I know which cell the user is trying to edit? and BTW how do I access that property?
Or should I use another strategy?
--
François
François
Re: User input in datagrid
I'm adding another constraint: I want the datagrid lines to catch double clicks to go to another card (that shows the detailed data of the line). What's the best practice for this case where I want the grid to be both edited and catch double clicks?
--
François
François
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: User input in datagrid
With a Data Grid you can define event handlers (i.e. mouseDoubleUp, mouseUp, etc.) just like you would for other controls. The difference is that there are two primary locations you can define those handlers:
1) The data grid script.
2) The behavior script (for a row or column).
mouseDoubleUp
I would put your mouseDoubleUp handler in the data grid script. Take a look at this lesson that talks about getting data for a row.
How Do I Get Data Associated With a Row or Column?
A mousedoubleUp might look something like this if placed in the data grid script:
Editing
To see how editing is currently handled for a table you can look at the default script for rendering data to a cell. The mouseDoubleUp handler shows how editing is handled.
How Do I Override the Default Behavior For Rendering Data to a Cell?
You could modify the default behavior so that editing was only allowed for the columns you are interested in. The default code is:
Just update the if statement so that it checks to see if the dgColumn of me is not "amountRemaining".
Allow editing property
The API info in the docs shows how to access properties. You are looking for the "allow editing" property.
Data Grid Properties
1) The data grid script.
2) The behavior script (for a row or column).
mouseDoubleUp
I would put your mouseDoubleUp handler in the data grid script. Take a look at this lesson that talks about getting data for a row.
How Do I Get Data Associated With a Row or Column?
A mousedoubleUp might look something like this if placed in the data grid script:
Code: Select all
on mouseDoubleUp pBtnNum
if pBtnNum is 1 then
put GetDataOfIndex(the dgHilitedIndex of me, YOUR_UNIQUE_VALUE) into theUniqueValue
-- Load card with record...
end if
end mouseDoubleUp
To see how editing is currently handled for a table you can look at the default script for rendering data to a cell. The mouseDoubleUp handler shows how editing is handled.
How Do I Override the Default Behavior For Rendering Data to a Cell?
You could modify the default behavior so that editing was only allowed for the columns you are interested in. The default code is:
Code: Select all
on mouseDoubleUp pMouseBtnNum
if pMouseBtnNum is 1 then
if the dgProps["allow editing"] of the dgControl of me \
and the dgColumnIsEditable[the dgColumn of me] of the dgControl of me then
-- Edit field contents if the user double-clicks
EditCellOfIndex the dgColumn of me, the dgIndex of me
exit mouseDoubleUp
end if
end if
pass mouseDoubleUp
end mouseDoubleUp
Allow editing property
The API info in the docs shows how to access properties. You are looking for the "allow editing" property.
Data Grid Properties
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: User input in datagrid
Thanks Trevor. I did my homework (read and experiment)
but am still stuck with the following. I have this array myData which I map to the grid myGrid:
I can reflect changes to index 2 column 2 of myData to myGrid with something like
But what I really need is to let the user change the grid then reflect the change to myData. To add a line, I have a "+" btn that inserts a new line and lets the user type data in it
Then the user can type anything in the new line, or in other lines. This is standard behaviour. My problem now is to catch a user modification of a cell so that I can modify my data accordingly. Do I have to reprogram the entire behaviour of the grid? or should I do each time? this seems time-consuming, and when should I do that?

Code: Select all
set the dgData of group "myGrid" to myData
Code: Select all
dispatch "SetDataOfindex" to group "myGrid" with 2,"Col2" , 0
dispatch "RefreshList" to group "myGrid"
Code: Select all
get the keys of myData
sort it numeric descending
put 1 + line 1 of it into newIndex
put "type something in this line" into myData[newIndex]["col1"]
put "type something in this line" into myData[newIndex]["col2"]
dispatch "AddData" to group "myGrid" with myData[newIndex] , 0
dispatch "EditCellOfIndex" to group "myGrid" with "Col1" ,newIndex
Code: Select all
put the dgData of group "myGrid" into myData
--
François
François
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: User input in datagrid
Here is a lesson from the manual that shows how to save data to an external data source.
How Do I Save Changes The User Makes In An Editor Field To An External Data Source?
How Do I Save Changes The User Makes In An Editor Field To An External Data Source?
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