How to change the Properties for read only by dynamic

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello everyone,
I have the code,

public bool CanLoad
{
get
{
return _canLoad;
}
set
{
_canLoad = value;
}
}
public string LoadText
{
get
{
return _loadText;
}
set
{
_loadText = value;
}
}
i want to let it like this, if the property of CanLoad set to false, the
property of LoadText is readonly.
Can i do it that.Thank you.
 
If I understand what you are looking for correctly it is to only allow
writing to the LoadText property if the CanLoad property it set to true.
If that is the case then you should surround the contents of the
LoadText property with an if statement that checks against the CanLoad
property. Something like:

public string LoadText
{
get
{
return _loadText;
}
set
{
if (this.CanLoad == true)
{
_loadText = value;
}
else
{
//do what you want if loading isn't allowed
}
}
}
 
Thank you.
but, this propery is in a control, so i want it that if the CanLoad is
false, the user can not input data to this propery in the properies panel.

-------------------------------------------------------------------------------------------
 
Back
Top