How do I position treeview to initially show 1st node added.

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

Guest

I'm adding twenty nodes (Parent and child) to a tree view. Only 10 items are
viewable in the window at at time. So when it initially shows the tree, it
shows the last ten items forcing me to use the scroll bar to show the first
10 items.

How do I change it to initially show the 1st ten items.
I'm using a datareader to populate the treeview.
 
How do I change it to initially show the 1st ten items.

The TreeNode class has an EnsureVisible method. Try calling it for the
first node.


Mattias
 
Thanks,

FYI: Here's the code I used after I finished populating the tree (sHistory
is the treeview contorl).

TreeNode firstNode = sHistory.Nodes[0];
if (!firstNode.IsVisible)
{
firstNode.EnsureVisible();
}
 
Thanks,

FYI: Here's the code I used after I finished populating the tree (sHistory
is the treeview contorl).

TreeNode firstNode = sHistory.Nodes[0];
if (!firstNode.IsVisible)
{
firstNode.EnsureVisible();
}
 
Just in case, you may want to check to make sure that
sHistory.Nodes.Count > 0

Just curious, why the s before History? From most of the code i've seen
other people setting the first letter to the datatype but i guess i was
completely wrong? what does the s normally mean?

Thanks,

FYI: Here's the code I used after I finished populating the tree (sHistory
is the treeview contorl).

TreeNode firstNode = sHistory.Nodes[0];
if (!firstNode.IsVisible)
{
firstNode.EnsureVisible();
}

:

The TreeNode class has an EnsureVisible method. Try calling it for the
first node.


Mattias
 
Good tip, thanks.

As far as the s, I put s in front of all my screen fields. I manually move
the mix of table values from datasets and output parameters(retrieved from
stored procedures) and move them into the screen fields. The screen field
name is the same as the file field name. I created a stored procedure that
generates the code to map the values into the screen fields that I can cut
and paste into the code, along with a function to handle nulls automatically,
both incoming and outgoing.

I could have used the same name, without the s, but this helps me keep track
of when I'm refering to one of the screen fields, instead of some calculated
field.

I also created custom controls for the various types of screen fields (like
date, email, currency, name, address, etc) that ensures that valid data is
entered, reformats the entered data if valid, and has properties with the
actual value for that datatype, along with built in security to ensure the
user has access to that control.

So, I just found it easier to move the values from and to the database when
the fields weren't bound to a datatable. I supposed I should have used 'f'
for form, but 's' looks better in front of the fields and I keep wanting to
call them screens.


Benny Raymond said:
Just in case, you may want to check to make sure that
sHistory.Nodes.Count > 0

Just curious, why the s before History? From most of the code i've seen
other people setting the first letter to the datatype but i guess i was
completely wrong? what does the s normally mean?

Thanks,

FYI: Here's the code I used after I finished populating the tree (sHistory
is the treeview contorl).

TreeNode firstNode = sHistory.Nodes[0];
if (!firstNode.IsVisible)
{
firstNode.EnsureVisible();
}

:

How do I change it to initially show the 1st ten items.

The TreeNode class has an EnsureVisible method. Try calling it for the
first node.


Mattias
 
Here's the code after testing for data and a slight modification to what I
had earlier.

if (sHistory.Nodes.Count > 0)
{
sHistory.ExpandAll();
sHistory.Nodes[0].EnsureVisible();
}


Vern said:
Thanks,

FYI: Here's the code I used after I finished populating the tree (sHistory
is the treeview contorl).

TreeNode firstNode = sHistory.Nodes[0];
if (!firstNode.IsVisible)
{
firstNode.EnsureVisible();
}


Mattias Sjögren said:
The TreeNode class has an EnsureVisible method. Try calling it for the
first node.


Mattias
 
Back
Top