datagrid updating a row

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
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

datagrid updating a row

Post by jalz » Fri May 29, 2015 11:44 pm

Hi Guys,

Need some advice. I've got a datagrid (table) called dg_charge_rate and I'd like to update a specific row. Previously the way handled it was by deleting the row and then adding a new row with the old ID. The drawback of this method was that the new item would be added to the end of the row. I've been reading up on the datagrid api and I think SetDataOfLine should allow me to update the row. I've included my code below, anyone point me where I'm going wrong with that particular line?

Cheers
Jalz


Code: Select all


put fld "fld_charge_description" into theDataA["charge_description"]
   put fld "fld_charge_rate" into theDataA["charge_rate"]
   put the label of btn "cb_chargeable" into theDataA["chargeable"]
   put fld "fld_charge_rate_lineno" into theDataA["chargeID"]
   
   put fld "fld_charge_rate_lineno" into tLineNo
   
   if tLineNo is an integer then
      --send "DeleteLine tLineNo" to group "dg_charge_rates"
      dispatch SetDataOfLine to grp "dg_charge_rates" with  tLineNo, theDataA
   else
      dispatch "AddData" to group "dg_charge_rates" with theDataA
   end if
   
   -- refresh the datagrid
   dispatch "RefreshIndex" to group "dg_charge_rates" with the dgHilitedIndex of group "dg_charge_rates"
   


bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: datagrid updating a row

Post by bangkok » Sat May 30, 2015 8:35 am

I've added an "update" part to my DG examples stack.

2 methods are described : dgIndex and dgDataOfIndex.

Might help.
Attachments
DG_EXAMPLES_1_5.zip
(65.52 KiB) Downloaded 516 times

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: datagrid updating a row

Post by sritcp » Sat May 30, 2015 5:40 pm

jalz wrote:

Code: Select all

.....................
      dispatch SetDataOfLine to grp "dg_charge_rates" with  tLineNo, theDataA
   ................................
Try adding quotes to the command:
dispatch "SetDataOfLine" to ....

Regards,
Sri.

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: datagrid updating a row

Post by jalz » Sat May 30, 2015 9:12 pm

Thanks Guys,

@sritcp putting quotes around the command didn't work. However, that sample file you posted bangkok was excellent - it showed me how to deal with and manipulate data in the datagrid.

Jalz

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”