 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Rick Jamieson Guest
|
Posted: Mon Jan 26, 2004 2:02 pm Post subject: How to select a treenode |
|
|
I am trying to select the first node in my treeview, my code
compiles in the OnShow event. But i keep getting an error, can
someone tell me if this is correct?
void __fastcall TForm1::FormShow(TObject *Sender)
{
if(TreeView1->Items->Count > 0)
TreeView1->Selected->Item[0];
TreeView1->SetFocus(); // error occurs here
TreeView1Click(this);
}
Thanks
Rick.
|
|
| Back to top |
|
 |
Pete Fraser Guest
|
Posted: Mon Jan 26, 2004 5:39 pm Post subject: Re: How to select a treenode |
|
|
void __fastcall TForm1::FormShow(TObject *Sender)
{
if(TreeView1->Items->Count > 0)
TreeView1->Selected = TreeView1->Selected->Item[0]; <<<< this
line is wrong
TreeView1->SetFocus(); // error occurs here <<<<< not sure about this -
looks OK
TreeView1Click(this);
}
"Rick Jamieson"
| Quote: |
I am trying to select the first node in my treeview, my code
compiles in the OnShow event. But i keep getting an error, can
someone tell me if this is correct?
void __fastcall TForm1::FormShow(TObject *Sender)
{
if(TreeView1->Items->Count > 0)
TreeView1->Selected->Item[0];
TreeView1->SetFocus(); // error occurs here
TreeView1Click(this);
}
Thanks
Rick.
|
|
|
| Back to top |
|
 |
Rick Jamieson Guest
|
Posted: Mon Jan 26, 2004 6:02 pm Post subject: Re: How to select a treenode |
|
|
| Quote: | What is the actual error message? Based on your code, I would guess that it
is something like "cannot focus a hidden window", correct?
|
What i got was an AccessViolation error, i didn't get the
"cannot focus a hidden window". The example you provided
did the trick, even when i used the following i still got
the AV on the second line. Samme problem with the code that
i had posted before.
if(TreeView1->Items->Count > 0)
TreeView1->Selected = TreeView1->Selected->Item[0];
but this worked for sure.
TreeView1->Selected = TreeView1->Items->GetFirstNode();
Thanks for the help
Rick
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Jan 26, 2004 6:45 pm Post subject: Re: How to select a treenode |
|
|
"Rick Jamieson" <rjamieson2335 (AT) yahoo (DOT) com> wrote
| Quote: | I am trying to select the first node in my treeview, my code
compiles in the OnShow event. But i keep getting an error, can
someone tell me if this is correct?
|
What is the actual error message? Based on your code, I would guess that it
is something like "cannot focus a hidden window", correct?
| Quote: | void __fastcall TForm1::FormShow(TObject *Sender)
|
The OnShow event triggers *before* the form is actually made visible
onscreen.
| Quote: | if(TreeView1->Items->Count > 0)
TreeView1->Selected->Item[0];
|
That code has no effect. Assuming that the Selected property is not NULL to
begin with, you are simply retreiving a pointer to the selected node's first
child, but not actually doing anything with it. You probably meant to do
this instead:
TreeView1->Selected = TreeView1->Items->GetFirstNode();
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Jan 26, 2004 8:09 pm Post subject: Re: How to select a treenode |
|
|
"Rick Jamieson" <rjamieson2335 (AT) yahoo (DOT) com> wrote
| Quote: | The example you provided did the trick, even when i
used the following i still got the AV on the second line.
|
The Selected property is most likely still NULL at the time, thus you are
accessing an invalid pointer.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|