Board index » cppbuilder » Why does SelectAll not working?

Why does SelectAll not working?


2004-03-07 09:32:47 PM
cppbuilder13
Hi all,
On my form there is one Edit Box, in this edit i have is a short
text, in the start of my code i have this lines -
Form1->MyEdit->SelStart = 0;
Form1->MyEdit->SelLength = Form1->MyEdit->Text.Length();
Form1->MyEdit->SelectAll();
Form1->MyEdit->Refresh();
I expected that after running this lines i will see the text in
the Edit box selected (in Blue color like i selected it with my
mouse) , but although this lines of code are executed i don't
see any part of the text selected in the edit box, it's stays
black text on a normal white background.
The question is - why? .....
Thanks,
Ramy
 
 

Re:Why does SelectAll not working?

"Ramy" < XXXX@XXXXX.COM >wrote:
Quote

Whenever you reference a member of a class, as long as you are
doing so from within the class, you don't need to qualifiy it
with the class name.
In other words, if the line:
Form1->MyEdit->SelStart = 0;
is contained within the Form1 class, then you can write the
line as such:
MyEdit->SelStart = 0;
Quote
[...] although this lines of code are executed
Are you sure that the code is executed? While it could be
coded better, I see no reason for it not to work. Try moving
it to a button click just to be sure:
void __fastcall TForm1::Button1Click(TObject* Sender)
{
ShowMessage( "About to set the edit" );
MyEdit->SelStart = 0;
MyEdit->SelLength = MyEdit->Text.Length();
OR but not both
MyEdit->SelectAll();
}
~ JD
 

Re:Why does SelectAll not working?

You must either set focus to the edit-field (MyEdit->SetFocus()) or set the
HideSelection property of MyEdit to false if the selection should be visible
without focus.
Palle
"JD" < XXXX@XXXXX.COM >skrev i en meddelelse
Quote

"Ramy" < XXXX@XXXXX.COM >wrote:
>

Whenever you reference a member of a class, as long as you are
doing so from within the class, you don't need to qualifiy it
with the class name.

In other words, if the line:

Form1->MyEdit->SelStart = 0;

is contained within the Form1 class, then you can write the
line as such:

MyEdit->SelStart = 0;

>[...] although this lines of code are executed

Are you sure that the code is executed? While it could be
coded better, I see no reason for it not to work. Try moving
it to a button click just to be sure:

void __fastcall TForm1::Button1Click(TObject* Sender)
{
ShowMessage( "About to set the edit" );
MyEdit->SelStart = 0;
MyEdit->SelLength = MyEdit->Text.Length();
OR but not both
MyEdit->SelectAll();
}

~ JD

 

{smallsort}

Re:Why does SelectAll not working?

"Palle Meinert" < XXXX@XXXXX.COM >wrote:
Quote
You must either set focus to the edit-field (MyEdit->SetFocus()) or set the
HideSelection property of MyEdit to false if the selection should be visible
without focus.
Good one. It didn't occure to me that even if it were the only
control on the form that it wouldn't have focus.
~ JD
 

Re:Why does SelectAll not working?

Thanks very much for your help.
"JD" < XXXX@XXXXX.COM >wrote:
Quote

"Palle Meinert" < XXXX@XXXXX.COM >wrote:
>You must either set focus to the edit-field (MyEdit->SetFocus()) or set the
>HideSelection property of MyEdit to false if the selection should be visible
>without focus.

Good one. It didn't occure to me that even if it were the only
control on the form that it wouldn't have focus.

~ JD