Click here to Skip to main content
16,005,491 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: DataGridView Scrolling Pin
Dave Kreskowiak27-Sep-06 5:41
mveDave Kreskowiak27-Sep-06 5:41 
GeneralRe: DataGridView Scrolling Pin
Are Jay27-Sep-06 6:36
Are Jay27-Sep-06 6:36 
QuestionNotify application Pin
rcyril27-Sep-06 3:54
rcyril27-Sep-06 3:54 
AnswerRe: Notify application Pin
Dave Kreskowiak27-Sep-06 5:33
mveDave Kreskowiak27-Sep-06 5:33 
QuestionAPI Pin
samira forooghi27-Sep-06 3:44
samira forooghi27-Sep-06 3:44 
AnswerRe: API Pin
Dave Kreskowiak27-Sep-06 5:28
mveDave Kreskowiak27-Sep-06 5:28 
QuestionSorting Treeview nodes in VB 2005 Pin
IainM127-Sep-06 3:11
IainM127-Sep-06 3:11 
AnswerRe: Sorting Treeview nodes in VB 2005 Pin
Dave Kreskowiak27-Sep-06 8:58
mveDave Kreskowiak27-Sep-06 8:58 
The existing TreeView already supports custom sorting, so it's no wonder you can't find a replacement control.

The TreeViewNodeSorter is not a method, but a property. It's expecting an instance of a class that you write that implements the IComparer interface. All you're doing is supplying a method to compare two arguments (Nodes) that the Treeview wants you to compare, comparing them yourself, returning a value (-1, 0, or 1) that says in which order the first and second arguments relate to each other. For example:
Imports System.Collections
 
Public Class MyNodeSorter
    Implements IComparer
 
    <font color=green>' You MUST supply the code for the Compare method using this exact function header!!</font>
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
        <font color=green>' All you do is compare the objects you get (they should always be TreeNodes).
        ' First, cast the Objects you get to TreeNodes.</font>
        Dim x As TreeNode = CType(x, TreeNode)
        Dim y As TreeNode = CType(y, TreeNode)
 
        <font color=green>' Then compare the Text properties of each node.  Since the String class already
        ' supplies a Comparer implementation that works on strings (duh!), just use that
        ' to do the work for you and return the value that it returns.</font>
        Return String.Compare(x.Text, y.Text)
    End Function
End Class

Docs on String.Compare(string, string)[^]

So, all you have to do is create an instance of this class and pass it to the TreeViewNodeSorter property, say in Form_Load, or in a "Sort" button click event handler:
TreeView1.TreeViewNodeSorter = New MyNodeSorter()





Dave Kreskowiak
Microsoft MVP - Visual Basic


GeneralRe: Sorting Treeview nodes in VB 2005 Pin
IainM128-Sep-06 0:23
IainM128-Sep-06 0:23 
GeneralRe: Sorting Treeview nodes in VB 2005 Pin
Dave Kreskowiak28-Sep-06 2:07
mveDave Kreskowiak28-Sep-06 2:07 
QuestionData Environment Pin
Mphatso Nkando27-Sep-06 0:04
Mphatso Nkando27-Sep-06 0:04 
AnswerRe: Data Environment Pin
Dave Kreskowiak27-Sep-06 9:04
mveDave Kreskowiak27-Sep-06 9:04 
Questionhow to automate selection of radio buttons using vb.net Pin
k_satish26-Sep-06 23:44
k_satish26-Sep-06 23:44 
QuestionPlease help Pin
minniemooo26-Sep-06 23:33
minniemooo26-Sep-06 23:33 
AnswerRe: Please help Pin
jhoga27-Sep-06 5:19
jhoga27-Sep-06 5:19 
Questionproblem with serial port and cross threads Pin
Rey999926-Sep-06 23:08
Rey999926-Sep-06 23:08 
AnswerRe: problem with serial port and cross threads Pin
Rey999926-Sep-06 23:44
Rey999926-Sep-06 23:44 
QuestionTransparent Label Pin
morteza5726-Sep-06 21:12
morteza5726-Sep-06 21:12 
GeneralRe: Transparent Label Pin
Guffa26-Sep-06 21:34
Guffa26-Sep-06 21:34 
AnswerRe: Transparent Label Pin
The ANZAC26-Sep-06 23:19
The ANZAC26-Sep-06 23:19 
GeneralRe: Transparent Label Pin
morteza5726-Sep-06 23:33
morteza5726-Sep-06 23:33 
GeneralRe: Transparent Label Pin
Dave Kreskowiak27-Sep-06 2:36
mveDave Kreskowiak27-Sep-06 2:36 
GeneralRe: Transparent Label Pin
morteza5727-Sep-06 20:21
morteza5727-Sep-06 20:21 
GeneralRe: Transparent Label Pin
Dave Kreskowiak28-Sep-06 2:10
mveDave Kreskowiak28-Sep-06 2:10 
QuestionNO MINIMIZE Pin
K edar V26-Sep-06 19:59
K edar V26-Sep-06 19:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.