2 Replies - 481 Views - Last Post: 21 December 2010 - 10:35 AM Rate Topic: -----

#1 rapo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 27-November 08

Access local controls from another methods

Posted 21 December 2010 - 10:19 AM

I have a method which creates a form by code(textboxes,labels,etc) and everything is local in the method, but I want to access the controls from another methods to get the values from textboxes. How can I make this? The form is used to make an update to a tabel from a mysql table, but when the form loads the values of the textboxes are loaded with the actual values and when I press Reload I want the table to be updated with the new values.
Is This A Good Question/Topic? 0
  • +

Replies To: Access local controls from another methods

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4311
  • View blog
  • Posts: 7,467
  • Joined: 08-June 10

Re: Access local controls from another methods

Posted 21 December 2010 - 10:29 AM

You'll need to either make the references to those TextBoxes in a wider scope (perhaps global to the class) or will need to add them in the Form designer instead of in code.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,356
  • Joined: 02-June 10

Re: Access local controls from another methods

Posted 21 December 2010 - 10:35 AM

Going on from insertAlias' statement....

It sounds like you aren't using any properties. It sounds like you are just throwing the data directly into the textboxes and other GUI elements in your one method, then you have no way to reach them elsewhere. Basically it just sounds like really bad planning/logic, and now you are having to write a band-aide to cover the problem.

Consider creating public properties for the information you want to go into the textboxes. The properties then get and set the values.


public string CustomerName
{
   get { return textBox1.Text; }
   set { textBox1.Text = value; }
}


The tutorials below walk through making an application including properties, inheritance, custom events and custom controls.
Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
[
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1