By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

changing UI state generate UI events

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
"# 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

P: n/a
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

P: n/a
"# 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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.