473,324 Members | 2,511 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,324 software developers and data experts.

changing UI state generate UI events

Hello,

When we update an UI control by code, that control generates a event.
For example, if we make a CheckBox Checked, then the CheckedChanged event is fired.
That is a goog behavior, but not at the first time (initialization).

Here the scenario :

<code>
SomeObject data ;
....
void UpdateData2UI()
{
this.checkbox.checked = data.IsPlaying ;
}
void checkbox_CheckedChanged(...)
{
data.IsPlaying = this.checkbox.checked ;
}
</code>

At UI initialization data.IsPlaying is "read" then "write" without necessity.
It could be a bad stuff if data.IsPlaying has to do some stuff.

Is the only solution is to add a test in checkbox_CheckedChanged ??
Like :
<code>
void checkbox_CheckedChanged(...)
{
if( this.checkbox.checked != data.IsPlaying )
{
data.IsPlaying = this.checkbox.checked ;
}
}
</code>

How do you do for that situation ?

I hope my explanation are clear enough ...

cyrille
Feb 3 '06 #1
6 1691
"# Cyrille37 #" <cy*******@free.fr> a écrit dans le message de news:
ed**************@TK2MSFTNGP14.phx.gbl...

| When we update an UI control by code, that control generates a event.
| For example, if we make a CheckBox Checked, then the CheckedChanged event
is fired.
| That is a goog behavior, but not at the first time (initialization).

You really ought to make the UI update itself based on the state of the
object, not the other way around. Try to set the Checked state based on the
IsPlaying property when you initialise the form.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Feb 3 '06 #2
Joanna Carter [TeamB] :
"# Cyrille37 #" <cy*******@free.fr> a écrit dans le message de news:
ed**************@TK2MSFTNGP14.phx.gbl...

| When we update an UI control by code, that control generates a event.
| For example, if we make a CheckBox Checked, then the CheckedChanged event
is fired.
| That is a goog behavior, but not at the first time (initialization).

You really ought to make the UI update itself based on the state of the
object, not the other way around. Try to set the Checked state based onthe
IsPlaying property when you initialise the form.


thanks for your help.

That is the form (an UserControl in fact) is always present.
In another UserControl when selected a Item in a TreeView, I'm refreshingdata.
So the Checked state could not be set in Form/UserControl initialization.

cyrille

Feb 3 '06 #3
"# Cyrille37 #" <cy*******@free.fr> a écrit dans le message de news:
e3**************@TK2MSFTNGP12.phx.gbl...

| That is the form (an UserControl in fact) is always present.
| In another UserControl when selected a Item in a TreeView, I'm refreshing
data.
| So the Checked state could not be set in Form/UserControl initialization.

Then I would suggest that you hold a local variable that is set to the
selected item in the TreeView. In the event handler that detects the change
in the TreeView, you can then set the local variable and update the
CheckBox.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Feb 3 '06 #4
Joanna Carter [TeamB] a écrit :
"# Cyrille37 #" <cy*******@free.fr> a écrit dans le message de news:
e3**************@TK2MSFTNGP12.phx.gbl...

| That is the form (an UserControl in fact) is always present.
| In another UserControl when selected a Item in a TreeView, I'm refreshing
data.
| So the Checked state could not be set in Form/UserControl initialization.

Then I would suggest that you hold a local variable that is set to the
selected item in the TreeView. In the event handler that detects the change
in the TreeView, you can then set the local variable and update the
CheckBox.
Yes, it's what I do.
But when I'm updating the checkbox, in response the checkbox fire an event which
update data ... The only solution I've found is to compare checkbox stateand
data state, if they are different I update data.

cyrille

Joanna


Feb 3 '06 #5
SP

"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:ed**************@TK2MSFTNGP14.phx.gbl...
Hello,

When we update an UI control by code, that control generates a event.
For example, if we make a CheckBox Checked, then the CheckedChanged event
is fired.
That is a goog behavior, but not at the first time (initialization).

Here the scenario :

<code>
SomeObject data ;
...
void UpdateData2UI()
{
this.checkbox.checked = data.IsPlaying ;
}
void checkbox_CheckedChanged(...)
{
data.IsPlaying = this.checkbox.checked ;
}
</code>

At UI initialization data.IsPlaying is "read" then "write" without
necessity.
It could be a bad stuff if data.IsPlaying has to do some stuff.

Is the only solution is to add a test in checkbox_CheckedChanged ??
Like :
<code>
void checkbox_CheckedChanged(...)
{
if( this.checkbox.checked != data.IsPlaying )
{
data.IsPlaying = this.checkbox.checked ;
}
}
</code>

How do you do for that situation ?


There are a few options. One is to set the event handlers not at design time
but at run time. Then the order of displaying your data is remove handlers,
update your controls and then add the handlers. Second option is to have a
bool flag like loadingData that you check in each event handler like
if(loadingData) return;. Third option is to use another event like Leave on
some controls where it is not really necessary for the changes that are made
to immediately update the state of your application but rather update when
the user has finished and leaves the control to do something else so the
Leave indicates "I have finished".

HTH

SP
Feb 3 '06 #6
SP a écrit :
"# Cyrille37 #" <cy*******@free.fr> wrote in message
news:ed**************@TK2MSFTNGP14.phx.gbl...
Hello,

When we update an UI control by code, that control generates a event.
For example, if we make a CheckBox Checked, then the CheckedChanged event
is fired.
That is a goog behavior, but not at the first time (initialization).

How do you do for that situation ?


There are a few options. One is to set the event handlers not at designtime
but at run time. Then the order of displaying your data is remove handlers,
update your controls and then add the handlers. Second option is to have a
bool flag like loadingData that you check in each event handler like
if(loadingData) return;. Third option is to use another event like Leave on
some controls where it is not really necessary for the changes that aremade
to immediately update the state of your application but rather update when
the user has finished and leaves the control to do something else so the
Leave indicates "I have finished".

Thank you very much for your clear explanation of choices.

Now I've material for thinking ;o)

bye
cyrille

Feb 3 '06 #7

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

Similar topics

6
by: iwearwatches | last post by:
Group, What a root canal. Here is what I have: I have a page that has several layers that I will either show/hide based on a graphic/tab that the user clicks. (works perfectly)
2
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
4
by: KK | last post by:
Hi All... For my purpose, I need to handle listbox selection changed event.I must be notified before changing occurs and after.After I can handle using SelectedIndexChanged event.Is there anyway...
5
by: Sean | last post by:
Problem with sessions I have created an application without concern for sessions. As it turns out I think that might be my undoing. What I have: I have an online quiz. I don’t need to know...
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
4
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I...
3
by: thomson | last post by:
Hi All, i do have an website with the URL http://localhost/application/ASEAN-ANZ, Once i hit the application, it goes to the Global.asax. but after that if i tried to change the URL...
3
by: galathaea | last post by:
it surprises me how often engineers confuse states with actions i think this is the fundamental reification behind procedural statemess and this mistake infects a lot of great projects with...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.