Page 1 of 1

DataGrid Form edit field from button outside of datagrid

Posted: Mon Feb 20, 2023 9:51 pm
by OriginalPaladin
Hey everyone,

I'm new to both the forums here as well as LiveCode. I've been playing with a DataGrid, successfully populating it from a SQLite database. I have a form with a datagrid on it (currently just named "DataGrid 1") and some buttons ("Add Record", "Delete Record", and "Save Record") on it that are on the form, but not inside of the datagrid. I've been playing with the "Add Record" button, and I've been able to add a new row to the datagrid, and scroll it down to the new row. What I'm stuck on (and have been researching a lot today), is getting the focus set to the first field in the new row, so that the user can begin typing in the new data for that row. Here's the code I have currently:

Code: Select all

on mouseUp pMouseButton
   put NULL into theRowData
   put NULL into theColumnData
   put the dgNumberOfLines of group "DataGrid 1" + 1 into theLineNo
   dispatch "AddLine" to group "DataGrid 1" with theRowData, theColumnData, theLineNo
   dispatch "ScrollLineIntoView" to group "DataGrid 1" with theLineNo
// need a dispatch command here to EditFieldText of the "FullName" field in the datagrid or some other code that does this
end mouseUp
Any help with this would be greatly appreciated!

Re: DataGrid Form edit field from button outside of datagrid

Posted: Tue Feb 21, 2023 10:54 am
by Klaus
Hi OriginalPaladin,

welcome to the forum! :-)

Add this line:

Code: Select all

...
dispatch "EditCell" to group "DataGrid 1" with "Name of your first column here...",theLineNo
...
Best

Klaus

Re: DataGrid Form edit field from button outside of datagrid

Posted: Tue Feb 21, 2023 3:21 pm
by OriginalPaladin
Thank you Klaus,

Code: Select all

dispatch "EditCell" to group "DataGrid 1" with "FullName",theLineNo
while this doesn't give an error message, the cursor is still not blinking in the first field of the datagrid (FullName) so that the user can begin typing. Perhaps the row needs to be selected or hilited first, or something?

Re: DataGrid Form edit field from button outside of datagrid

Posted: Tue Feb 21, 2023 4:34 pm
by Klaus
Hm, I had used your script to test my answer and the cursor was blinking in the first cell
of the new line and I could start typing right away!?
See screenshot...

Re: DataGrid Form edit field from button outside of datagrid

Posted: Tue Feb 21, 2023 4:43 pm
by OriginalPaladin
Mine's actually a DataGrid Form if that makes any difference. Also, the field in mine is not actually the first field (I typed incorrectly), but since I'm using the field's name, I didn't think it mattered. Does it?

Re: DataGrid Form edit field from button outside of datagrid

Posted: Tue Feb 21, 2023 4:52 pm
by Klaus
OriginalPaladin wrote:
Tue Feb 21, 2023 4:43 pm
Mine's actually a DataGrid Form if that makes any difference.
It DOES, "editCell" will only work for datagrids of type TABLE.
Sorry, no idea if there is something like this that will work with FORMS.

Re: DataGrid Form edit field from button outside of datagrid

Posted: Tue Feb 21, 2023 5:04 pm
by OriginalPaladin
That explains things. Thanks so much for the help though Klaus!

I noticed that there is no horizontal scrollbar "stuff" allowed with DataGrid Forms, so perhaps this is another thing. At least I can scroll to the new row and hilite it...