brgerner
brgerner

Reputation: 4371

Remember control's text while being disabled

What is the best way to remember Text/Value of a control after it is enabled again?

In my special case I have a checkbox to enable/disable a NumericSpinBox.

When checkbox is switched to Checked=false: spinbox is disabled and the last value (e.g. 10) should be remembered and the text should be cleared.

When checkbox is switched to Checked=true: spinbox is enabled again and the remembered value (e.g. 10) is reassigned.

Ok, I could store the value in an extra field of my form or container control. But if there are several controls with remembering values the additional fields are too much overhead (in terms of readability) for so small feature IMO. So I hope you have better solutions.

Upvotes: 2

Views: 88

Answers (2)

Fadrian Sudaman
Fadrian Sudaman

Reputation: 6465

Define a Type that represent the fields that you want and create an object of that type that hold all the state of your UI element. Set the value manually on enable or use binding

Upvotes: 0

Amen Ayach
Amen Ayach

Reputation: 4348

You can store value in the Tag property of the numericbox or checkbox

Upvotes: 1

Related Questions