Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Delete control at runtime

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2007, 04:54 PM
Junior Member
 
Join Date: Jun 2007
Posts: 38
Default Delete control at runtime

Is there a way to delete a control at runtime and also a way to check if a control exists?

I have a list of buttons that are populated with text from a database and I name the buttons using a loop (ex. "BUTTON" & i, this gives me a list of buttons like BUTTON1, BUTTON2, etc.)

When I re-open the form, I need to delete the old buttons (because they link to old information) and start from scratch creating new buttons. How can I just check to see if the button exists and then delete all of the buttons from the form at runtime?
Reply With Quote
  #2 (permalink)  
Old 06-27-2007, 05:31 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

When you add the buttons, add their names to an ArrayList.
Now you will be able to check if a specific button exists.
Use the Dispose method to delete a control.
Something like:
For i = 0 To ArrayList1.Count-1
Control(ArrayList1.Item(i)).Dispose
Next
ArrayList1.Clear
Reply With Quote
  #3 (permalink)  
Old 06-27-2007, 05:34 PM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Is there a way to delete a control at run-time and also a way to check if a control exists?
You need to Dispose of the control. I'm not familiar with finding out whether the control exists in the first place though.
You could just try to Dispose of all the controls and trap/ignore the error that would be generated if the control wasn't present.
I also believe that Disposing of a Form will Dispose of all controls that were present on it. This may have changed with version 5 though??

EDIT: I replied at the samtime as Erel, sorry. As normal I prefer Erel's solution.

Regards,
RandomCoder.
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels

Last edited by RandomCoder : 06-27-2007 at 05:36 PM.
Reply With Quote
  #4 (permalink)  
Old 06-27-2007, 06:01 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

If the control doesn't exist a error is generated so u can use errorlabel to catch that..

I've done something similar like this:

sub controlsdispose
For i= 1 to whatever you like, but be sure to be over your last button i
ErrorLabel("Error")
Control("Button"&i).dispose
next i
error:
If u whant u can do something upon error
end sub
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
read and delete sms...how? Byak@ Questions (Windows Mobile) 1 10-12-2008 06:42 PM
Delete from SQLlite ceaser Questions (Windows Mobile) 2 08-24-2008 07:29 AM
Delete a row in a table and simultaneously delete it in the database gonzamax Questions (Windows Mobile) 2 12-25-2007 01:23 PM
Delete Control and Delete Form Items alfcen Basic4ppc Wishlist 3 10-05-2007 12:09 PM
Runtime control manipulation Erel Code Samples & Tips 6 05-11-2007 01:19 PM


All times are GMT. The time now is 04:42 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0