How to update a container control in a Window

I have the following code as a method to save data in a ContainerControl

[code] app.karter.SQLExecute(“BEGIN TRANSACTION”)
Dim dr as new DatabaseRecord
dim rs as recordset = app.karter.SQLSelect("select * from mydriver where PK = "+ str(mydriverpk))

rs.Edit
rs.field(“name”).StringValue = trim(txtname.text)
rs.field(“licenseno”).StringValue = trim(txtlicenseno.text)
rs.field(“licenseex”).StringValue = trim(txtlicenseex.text)

rs.update

app.karter.commit
msgbox"Record has been Updated"[/code]

How do I update the containercontrol after the data has been saved to reflect the changes

Have tried Containercontrol.close and containercontrol.show , but close and show say “this item doen’t exist”

If the data is coming from the containercontrol, why do you need to update it? Wouldn’t it already contain the correct values?

I created a containercontrol and dropped it on the main tabbed window, I have placed a Method called updatedisplay in the open event of the Tabpanel and the paged is displayed corectly when the program is first run, the code for the updatedisplay method is

[code] Dim rs as RecordSet = app.karter.SQLSelect(“select * from mydriver Order by name”)
while not rs.eof
txtname.appendtext rs.Field(“name”).stringValue + endofline
popupmenu1.AddRow rs.Field(“name”).StringValue
popupmenu1.RowTag(popupmenu1.ListCount-1) = rs.Field(“PK”).IntegerValue

rs.MoveNext

wend
popupmenu1.ListIndex = 0[/code]

If I update the record or save a new record the new data is not displayed unless I close the program and reopen it, I am stuck and can’t find a solution.

Move the update sequence to a method of its own. Place an instance of the method called by name in the Open event, and include the same method call by name whenever you want to update the contents.

ie:
UpdateUI()

In your post you mentioned it is only called in the open event. The open event only fires one time when the application initializes.

You can invoke container methods from outside the container as well if the method is public as:

ContainerName1.UpdateUI()

If the commit was successful, the SQLSelect should render the new data with no problem. It’s good habit to check for errors when using databases. I see in the function first listed no error checking was performed.

ie)

If dbname.error then
Dbname.rollback
Msgbox “an error occurred”
Else
Dbname.commit
//we were successful
End if

Error checking helps greatly in debugging and tracking down problems later on.

Hi Matthew, the update method is in the methods of the container it is called UpdateDrivers.

Don’t know how to call it from outside the container.

I have the container inside a Tabpanel in the main window.

When you drop the container on the window, you give it a name (or let it default to a name like ContainerControl1). Use that name to call the method.

ContainerControl1.UpdateDrivers

Thanks Tim, so it would be MyDrivers1.UpDateDrivers, but where do I put it.

Thanks Shane.

Put it in the code that saves the changes to the database. At the end.

Alternately, if you can identify the parts of the container that need to be updated for this specific record (eg., which row of a listbox), you can add a separate method to update just the one record.

Hi Tim, done that didn’t work, I will try and explain what I have.

I have a Containercontrol called “Mydrivers” in there I have a save button with the following code on it.

[code] Dim dr as new DatabaseRecord
dim rs as recordset = app.karter.SQLSelect("select * from mydriver where PK = "+ str(mydriverpk))

dr.column(“name”) = trim(txtname.text)
dr.column(“licenseno”) = trim(txtlicenseno.text)
dr.column(“licenseex”) = trim(txtlicenseex.text)

app.karter.commit
msgbox"New Record Added"[/code]

Code has been shortened to save space, this method saves fine to the database.

I also have a Method in the container called UpDateDrivers.

[code] Dim rs as RecordSet = app.karter.SQLSelect(“select * from mydriver Order by name”)
while not rs.eof
txtname.appendtext rs.Field(“name”).stringValue + endofline
popupmenu1.AddRow rs.Field(“name”).StringValue
popupmenu1.RowTag(popupmenu1.ListCount-1) = rs.Field(“PK”).IntegerValue

rs.MoveNext

wend
popupmenu1.ListIndex = 0[/code]

There is also a Method called Save, this updates the record from a “update record button” it is called with the following

save(popupmenu1.RowTag(popupmenu1.ListIndex))

and the code for the save Method is

app.karter.SQLExecute("BEGIN TRANSACTION") Dim dr as new DatabaseRecord dim rs as recordset = app.karter.SQLSelect("select * from mydriver where PK = "+ str(mydriverpk)) rs.Edit rs.field("name").StringValue = trim(txtname.text) rs.field("licenseno").StringValue = trim(txtlicenseno.text) rs.field("licenseex").StringValue = trim(txtlicenseex.text) rs.field("transno").StringValue = trim(txttransno.text) rs.field("raceno") .StringValue= trim(txtraceno.text) rs.field("classes").StringValue = trim(txtclasses.text) rs.field("raceteam").StringValue = trim(txtraceteam.text) rs.field("sponsors").StringValue = trim(txtsponsors.text) rs.field("club").StringValue = trim(txtclub.text) rs.field("clubmemno").StringValue = trim(txtclubmemno.text) rs.field("clubwebsite").StringValue = trim(txtclubwebsite.text) rs.field("clubhometrack").StringValue = trim(txtclubhometrack.text) rs.field("clubemail").StringValue = trim(txtclubemail.text) rs.field("clubcontact").StringValue = trim(txtclubcontact.text) rs.field("clubmailing").StringValue = trim(txtclubmailing.text) rs.field("comments").StringValue = trim(txtcomments.text) rs.update app.karter.commit msgbox"Record has been Updated"

All the code I have works fine in the older version of the program, I am now trying to update the code using containercontrols and a main window with a tab panel, as it was previously all done with seperate windows.

I dropped the Containercontrol on the tab pannel and it is called Mydrivers1
When I add MyDrivers1.UpDateDrivers to the bottom of

Dim dr as new DatabaseRecord dim rs as recordset = app.karter.SQLSelect("select * from mydriver where PK = "+ str(mydriverpk)) dr.column("name") = trim(txtname.text) dr.column("licenseno") = trim(txtlicenseno.text) dr.column("licenseex") = trim(txtlicenseex.text) dr.column("transno") = trim(txttransno.text) app.karter.commit msgbox"New Record Added"

I get the Error
This item does not exist
Mydrivers.Updatedrivers ----The Error is on MyDrivers

Hope this makes sense, thanks

If this code is all in the MyDrivers container definition, simply call UpdateDrivers. No need for a prefix. The container knows nothing about MyDrivers1 on the window, and MyDrivers is not a valid instance. Use UpdateDrivers or Self.UpdateDrivers.

Ok thanks will give it a go.

Hi Tim, now having a problem with it doubling up the records in Popupmenu1 in the above code.

Clear the popupmenu’s list first. It won’t hurt to do so at startup.

PopupMenu1.DeleteAllRows