473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Attach external variable to control?

When working w/ forms and controls, in 95% of the cases, the value of the
control is used somewhere in the program (duh!).

However, there doesn't seem to be an easy way to attach a value variable to
that control the automatically handles synchronization of the value w/ the
contol.

Here is an example:

// some form
System.Windows.Forms.TextBox inputSearchString;

// some variable that holds the value of the input
string searchString;

Now, if I want to synchronize the value of the input w/ the string, I have to
go and create a couple of event handlers that copy the text box value to the
string if I want to ensure that the searchString is always current.

It seems that a better solution would be for something like an attach operation
that would couple and synchronize the values:

searchString.AttachTo(inputSearchString);

Now, whenever the value of inputSearchString changed, it would automatically
update the value in searchString.

Is there something in the language/framework that I've missed that would allow
this type of functionality, or must I just create a mess of event handlers?
Nov 15 '05 #1
4 2041

"Julie J." <unlisted@.> wrote in message news:403BCF29.1FE4A6CB@....
When working w/ forms and controls, in 95% of the cases, the value of the
control is used somewhere in the program (duh!).

However, there doesn't seem to be an easy way to attach a value variable
to
that control the automatically handles synchronization of the value w/ the
contol.

Here is an example:

// some form
System.Windows.Forms.TextBox inputSearchString;

// some variable that holds the value of the input
string searchString;

Now, if I want to synchronize the value of the input w/ the string, I have
to
go and create a couple of event handlers that copy the text box value to
the
string if I want to ensure that the searchString is always current.

It seems that a better solution would be for something like an attach
operation
that would couple and synchronize the values:

searchString.AttachTo(inputSearchString);

Now, whenever the value of inputSearchString changed, it would
automatically
update the value in searchString.

Is there something in the language/framework that I've missed that would
allow
this type of functionality, or must I just create a mess of event
handlers?


To achieve this with actual linking would require alot of work(it'd be based
on refelction and just not something I'd want to do). It'd have to be based
on fields, not variables. Such a mechanism would also start to tie variables
into other bits they shouldn't.

However, couldn't you simply use a property here? something like:

TextBox inputSearchString;
string searchString
{
get
{
return inputSearchString.Text;
}
set
{
inputSearchString.Text = value;
}
}


Nov 15 '05 #2
Daniel, thanks for the reply.

The motivation behind my quest is that a lot of the work that I do is based on
entities that exist beyond just their UI representation.

For example, defining a set of search parameters (search text, and 15-20 other
filtering parameters). I've encapsulated all of the parameters into a class,
and instances of that class are created, defined, archived, etc. and eventually
may display an interface for the user to make changes to the parametric
values. So, for that reason, it doesn't make sense to define the parameter
class in terms of UI elements. Further, since C# doesn't support MI, I can
define the UI in terms of the underlying parameter class.

At least w/ VS6 and prior, there was the ClassWizard for MFC that would
facilitate the hooking up of variables w/ a UI representation. I'm finding it
tedious (and error prone) to have to resort to event handling to perform the
required level of value synchronization.

Too bad there isn't an easier way in the language/framework...

"Daniel O'Connell [C# MVP]" wrote:

"Julie J." <unlisted@.> wrote in message news:403BCF29.1FE4A6CB@....
When working w/ forms and controls, in 95% of the cases, the value of the
control is used somewhere in the program (duh!).

However, there doesn't seem to be an easy way to attach a value variable
to
that control the automatically handles synchronization of the value w/ the
contol.

Here is an example:

// some form
System.Windows.Forms.TextBox inputSearchString;

// some variable that holds the value of the input
string searchString;

Now, if I want to synchronize the value of the input w/ the string, I have
to
go and create a couple of event handlers that copy the text box value to
the
string if I want to ensure that the searchString is always current.

It seems that a better solution would be for something like an attach
operation
that would couple and synchronize the values:

searchString.AttachTo(inputSearchString);

Now, whenever the value of inputSearchString changed, it would
automatically
update the value in searchString.

Is there something in the language/framework that I've missed that would
allow
this type of functionality, or must I just create a mess of event
handlers?


To achieve this with actual linking would require alot of work(it'd be based
on refelction and just not something I'd want to do). It'd have to be based
on fields, not variables. Such a mechanism would also start to tie variables
into other bits they shouldn't.

However, couldn't you simply use a property here? something like:

TextBox inputSearchString;
string searchString
{
get
{
return inputSearchString.Text;
}
set
{
inputSearchString.Text = value;
}
}

Nov 15 '05 #3
"Julie J." <unlisted@.> wrote in message news:403BDFA5.19B688F@....
Daniel, thanks for the reply.

The motivation behind my quest is that a lot of the work that I do is based on entities that exist beyond just their UI representation.

For example, defining a set of search parameters (search text, and 15-20 other filtering parameters). I've encapsulated all of the parameters into a class, and instances of that class are created, defined, archived, etc. and eventually may display an interface for the user to make changes to the parametric
values. So, for that reason, it doesn't make sense to define the parameter class in terms of UI elements. Further, since C# doesn't support MI, I can define the UI in terms of the underlying parameter class.

At least w/ VS6 and prior, there was the ClassWizard for MFC that would
facilitate the hooking up of variables w/ a UI representation. I'm finding it tedious (and error prone) to have to resort to event handling to perform the required level of value synchronization.

Too bad there isn't an easier way in the language/framework...


Julie,

Since you've encapsulated those parameters into a class, why can't you use
databinding to bind control values to your class members?

You might have some issues with synchronizing the BindingManagerBase and
figuring out the proper time to use EndCurrentEdit, but in general, this
seems to be the solution that .NET prescribes to your problem.

Erik
Nov 15 '05 #4

"Julie J." <unlisted@.> wrote in message news:403BDFA5.19B688F@....
Daniel, thanks for the reply.

The motivation behind my quest is that a lot of the work that I do is
based on
entities that exist beyond just their UI representation.

For example, defining a set of search parameters (search text, and 15-20
other
filtering parameters). I've encapsulated all of the parameters into a
class,
and instances of that class are created, defined, archived, etc. and
eventually
may display an interface for the user to make changes to the parametric
values. So, for that reason, it doesn't make sense to define the
parameter
class in terms of UI elements. Further, since C# doesn't support MI, I
can
define the UI in terms of the underlying parameter class.

At least w/ VS6 and prior, there was the ClassWizard for MFC that would
facilitate the hooking up of variables w/ a UI representation. I'm
finding it
tedious (and error prone) to have to resort to event handling to perform
the
required level of value synchronization.

Too bad there isn't an easier way in the language/framework...

Frankly, you will *always* be handling events in some way, all a wizard
would do is hide that from you. The framework level code required to do what
you want in a generic way would be complicated to say the least.

To achieve this sort of behaviour across *alot* of UI work, you may want to
look into your own code generator that achieves your target. This may be
possible in an easier way with C++ style templates, but they don't exist in
C#.

You may also want to look into databinding, it could well do what you want.
It is outside of my experiance however. "Daniel O'Connell [C# MVP]" wrote:

"Julie J." <unlisted@.> wrote in message news:403BCF29.1FE4A6CB@....
> When working w/ forms and controls, in 95% of the cases, the value of
> the
> control is used somewhere in the program (duh!).
>
> However, there doesn't seem to be an easy way to attach a value
> variable
> to
> that control the automatically handles synchronization of the value w/
> the
> contol.
>
> Here is an example:
>
> // some form
> System.Windows.Forms.TextBox inputSearchString;
>
> // some variable that holds the value of the input
> string searchString;
>
> Now, if I want to synchronize the value of the input w/ the string, I
> have
> to
> go and create a couple of event handlers that copy the text box value
> to
> the
> string if I want to ensure that the searchString is always current.
>
> It seems that a better solution would be for something like an attach
> operation
> that would couple and synchronize the values:
>
> searchString.AttachTo(inputSearchString);
>
> Now, whenever the value of inputSearchString changed, it would
> automatically
> update the value in searchString.
>
> Is there something in the language/framework that I've missed that
> would
> allow
> this type of functionality, or must I just create a mess of event
> handlers?


To achieve this with actual linking would require alot of work(it'd be
based
on refelction and just not something I'd want to do). It'd have to be
based
on fields, not variables. Such a mechanism would also start to tie
variables
into other bits they shouldn't.

However, couldn't you simply use a property here? something like:

TextBox inputSearchString;
string searchString
{
get
{
return inputSearchString.Text;
}
set
{
inputSearchString.Text = value;
}
}

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newsnet Customer | last post by:
Hi, Is an external variable a variable that is defined outside of a method? or a variable with the extern modifier prefixed to it? and what's the difference with external and global variables? ...
4
by: bhatiaajay | last post by:
I am new to JavaScript objects. The object creates a button with no events attached. Later I want to attach an event to the button created by this object. The event attaches a function in the...
0
by: bob | last post by:
Hello, I am trying to read paradox data in MS-access When I import or attach external DATA, I get this message 'Incorrect sort order' 'Ordre de tri incorrect ' (in french) Any ideas please...
3
by: Wizard | last post by:
In Access, using VBA, I am sending emails based on query results. These email include relevant information to a scheduled event the recipient is assigned to. This is working great. What I have...
4
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want...
6
by: Charles Law | last post by:
Suppose my application is running on a client machine, and they report an intermittent problem. It only occurs after the program has been running for a while, and then occasionally fails to perform...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the...
6
by: GaryDean | last post by:
I see some references on debugging by attaching to a process. There are MSDN articles that show how to attach to a process for debugging. However, I can find no info on how exactly to get the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.