Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Control nodes sorting  (Read 731 times)

0 Members and 1 Guest are viewing this topic.

Rumba

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
Control nodes sorting
« on: November 30, 2008, 08:48:25 AM »
First of all I have to say that your control looks very impressive.  :o

I have a newbie questions here.
I`m filling a tree by a local disk structure. So:
1) I need to place all folders above the files even if they are sorted!
2) I want to use your SoftSelect feature to show some file`s text info when a user hover mouse over the file

How can I accomplish that?

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: Control nodes sorting
« Reply #1 on: November 30, 2008, 12:38:24 PM »
Hello Rumba and welcome!

Thanks for your feedback. We do our best to make Flexible TreeView the best treeview-listview component on the market.

About your questions:
1) To accomplish that you should create a node class that will describe your files and folders.
Code: [Select]
class FileNode : Node
{
  public readonly bool IsFile;
  public readonly long FileSize;

  public FileNode(string pText, bool pIsFile, long pFileSize)
        : base(pText)
  {
    IsFile = pIsFile;
    FileSize = pFileSize;
  }
}

 Then fill the treeview by files and folders nodes:
Code: [Select]
FileNode node;
foreach (string dir in Directory.GetDirectories("c:\"))
{
  node = new FileNode(dir, false, 0);
  LoadDirectoryStructure(dir, node);
}

void LoadDirectoryStructure(string pDir, FileNode pParentNode)
{
  FileNode node;

  foreach (string dir in Directory.GetDirectories(pDir))
  {
    node = new FileNode(dir, false, 0);
    node.AttachTo(pParentNode);
    LoadDirectoryFiles(dir, node);
  }
}

private void LoadDirectoryFiles(string pDir, FileNode pParentNode)
{
  FileNode node;

  foreach (string file in Directory.GetFiles(pDir))
  {
     node = new FileNode(file, true, new FileInfo(file).Length);
     node.AttachTo(pParentNode);
  }
}
 

Then attach the event handler to the treeview`s NodePostCompareAudit event:
Code: [Select]
void tree_NodePostCompareAudit(FlexibleTreeView pTreeView, Node pNode1, Node pNode2, SortOrder pSortOrder, ref eNodeCompareResult pCompareResult)
{
FileNode node1, node2;

node1 = pNode1 as FileNode;
node2 = pNode1 as FileNode;
if(node1 != null && node2 != null)
{
  if(!node1.IsFile && node2.IsFile)
  {
     // place a folder above any file
     pCompareResult = eNodeCompareResult.Higher;
  }
  else if(node1.IsFile && !node2.IsFile)
  {
     // place a file below any folder
     pCompareResult = eNodeCompareResult.Lower;
  }
}
}

That`s all. So main trick is the NodePostCompareAudit event handler function here.

2) About your second question: I`m happy that you choose SoftSelect feature because it`s really useful feature for cases like yours.
So to do that:
a) Extend the FileNode class stated above (add the Description property and change the ctor):
Code: [Select]
public readonly string Description;

public FileNode(string pText, bool pIsFile, long pFileSize, string pDescription)
      : base(pText)
{
      IsFile = pIsFile;
      FileSize = pFileSize;
      Description = pDescription;
}

b) open the tree`s NodeControls designer in the Visual Studio Properties Window, add NodeExpandableTextBox node control and adjust the DataFieldName field of that node control to "Description" value. Here we bound the node class`s Description property with the node control which will show that data.

c) Everywhere where you are creating a FileNode instance pass a description for that particular node in ctor as stated above.

d) And final step is to enable SoftSelect hover style:
Code: [Select]
tree.Options.Selection.HoverStyle = eHoverStyle.SoftSelect;

That`s all. It was simple is`nt it?  ;)

If you have any questions feel free to ask it here and we`ll find a solution for you.
« Last Edit: December 01, 2008, 01:42:33 AM by Ruslan »

Rumba

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
Re: Control nodes sorting
« Reply #2 on: December 01, 2008, 05:23:13 AM »
Thank you.

 Rumba
 

Copyright © 2006-2012 ARMSoft. All rights reserved.