[Gambas-user] How top clearing a readonly textbox

Jussi Lahtinen jussi.lahtinen at gmail.com
Sat Nov 26 04:29:15 CET 2022


Sorry, this is correct:
bReadOnly = False
Try bReadOnly = ctl.ReadOnly

If bReadOnly = False Then
Try ctl.Clear
Endif



On Sat, Nov 26, 2022 at 5:27 AM Jussi Lahtinen <jussi.lahtinen at gmail.com>
wrote:

> Try bReadOnly = ctl.ReadOnly
>
> If bReadOnly = False Then
> Try ctl.Clear
> Endif
>
> Jussi
>
>
> On Sat, Nov 26, 2022 at 5:17 AM BB <adamnt42 at gmail.com> wrote:
>
>> Yeah, I over simplified my problem. I'm trying to clear a form by going
>> through all the controls and trying to "clear" them.
>>
>> As in
>>
>>     For Each ctl as Object in Me.controls   ' (ctl has to be an Object as it could be a control or it could be a container.)
>>         Try ctl.Clear
>>     Next
>>
>> Since I don't know what the ctl is I cant check if its read-only before
>> trying to clear it. As in I can't do
>>
>>     If ctl.ReadOnly Then Continue
>>
>> and obviously not
>>
>>     Try If ctl.ReadOnly Then Continue
>>
>> I know it could be done with a lot of complex checking for what type of
>> control each one is but I was trying to avoid that.
>>
>>     Dim thisTextBox as TextBox
>>     Dim thisTextArea as TextArea
>>     ' etc etc etc etc
>> ...
>>     For Each ctl as Object in Me.Controls
>> 	If ctl Is TextBox Then
>> 		thisTextBox=ctl
>> 		if not thisTextBox.ReadOnly then thisTextBox.Clear
>> 	Else If ctl Is TextArea
>> 		etc
>> 	Else If ctl Is MyCustomTextBox
>> 		etc
>> 	Else If ctl Is etc etc etc etc for up to 3 gazillion control types and custom control types
>> 		
>>
>>
>> I have attached a "simplified" demo. The actual case is a very complex
>> form with lots of controls including custom controls.
>>
>> bruce
>> On 26/11/22 12:51 pm, Jussi Lahtinen wrote:
>>
>> Might be simplest to check the read only status before calling Clear().
>> But this surely works:
>> Dim sText As String = TextBox1.Text
>> TextBox1.Clear
>> TextBox1.Text = sText
>>
>> The method _Change() is called after the change is done to the .Text thus
>> it is too late to stop.
>> Not sure if all this is wanted behavior.
>>
>>
>> Jussi
>>
>>
>>
>> On Sat, Nov 26, 2022 at 3:50 AM BB <adamnt42 at gmail.com> wrote:
>>
>>> As the help says, Textbox.Clear() "Clears the text". However, in the
>>> case where the textbox is ReadOnly then I don't want this to happen.
>>>
>>> I've tried several ways* but can't stop it. Any clues?
>>>
>>> b
>>>
>>> * overriding Clear, using Stop Event, even saving the original text and
>>> re-setting it
>>
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20221126/cc1bba44/attachment.htm>


More information about the User mailing list