text change question

J

Jassim Rahma

i have two textboxes.

txtHostName and txtHotTitle

when the user types in the txtHostName it automatically set the txtHostTitle
= txtHostName

until now it's ok..

now, i want if the user changed the value in txtHostTitle using the keyboard
or the mouse shortcuts (delete, cut, etc) which means i f the use chaned the
value in txtHostTitle in anyway then it should not update the txtHostTitle =
txtHostName

I have created a variable called host_titel_changed which is initially false
but i want to know how can i make it true when detecting any changes in the
txtHostTitle
 
M

Morten Wennevik

i have two textboxes.

txtHostName and txtHotTitle

when the user types in the txtHostName it automatically set the txtHostTitle
= txtHostName

until now it's ok..

now, i want if the user changed the value in txtHostTitle using the keyboard
or the mouse shortcuts (delete, cut, etc) which means i f the use chaned the
value in txtHostTitle in anyway then it should not update the txtHostTitle =
txtHostName

I have created a variable called host_titel_changed which is initiallyfalse
but i want to know how can i make it true when detecting any changes in the
txtHostTitle

Hi Jassim,

You can do this with DataBinding,

Have txtHostName bind to a property, for instance "Name";
Have txtHostTitle bind to another property, for instance "Title";
In Title's getter, check your flag, if set, read it's own value, otherwise, read Name

private string _name;
public string Name
{
get{ return _Name; }
set{ _name = value; }
}

private string _title;
bool host_title_changed;
public string Title
{
get
{
if(host_title_changed)
return _title;
else

return Name;
}
set
{
_title = value;
host_title_changed = true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top