DataGrid Form edit field from button outside of datagrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
OriginalPaladin
Posts: 6
Joined: Mon Feb 20, 2023 9:25 pm

DataGrid Form edit field from button outside of datagrid

Post by OriginalPaladin » Mon Feb 20, 2023 9:51 pm

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!

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: DataGrid Form edit field from button outside of datagrid

Post by Klaus » Tue Feb 21, 2023 10:54 am

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

OriginalPaladin
Posts: 6
Joined: Mon Feb 20, 2023 9:25 pm

Re: DataGrid Form edit field from button outside of datagrid

Post by OriginalPaladin » Tue Feb 21, 2023 3:21 pm

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?

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: DataGrid Form edit field from button outside of datagrid

Post by Klaus » Tue Feb 21, 2023 4:34 pm

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...
Attachments
editcell.png

OriginalPaladin
Posts: 6
Joined: Mon Feb 20, 2023 9:25 pm

Re: DataGrid Form edit field from button outside of datagrid

Post by OriginalPaladin » Tue Feb 21, 2023 4:43 pm

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?

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: DataGrid Form edit field from button outside of datagrid

Post by Klaus » Tue Feb 21, 2023 4:52 pm

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.

OriginalPaladin
Posts: 6
Joined: Mon Feb 20, 2023 9:25 pm

Re: DataGrid Form edit field from button outside of datagrid

Post by OriginalPaladin » Tue Feb 21, 2023 5:04 pm

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...

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”