Windows Mobile 6 - Treeview issues

robhermans

Member
Joined
Sep 26, 2009
Messages
6
Programming Experience
10+
Hi:
I am using VS 2005 with WM 6 professional SDK to develop PDA app. I am using the treeview ... a couple of problems:
1. When I loop thru the nodes to search for a node using the following code I only see the parent nodes whereas a nodecount gives 38 I have 3 parents, 6 children and 29 grandchildren.

MsgBox(tvFind.GetNodeCount(True))

For Each n As TreeNode In tvFind.Nodes
MsgBox("Looking for " & sFindItem)
MsgBox("this Node:" & UCase$(n.Text))
If InStr(UCase$(n.Text), sFindItem) > 0 Then
lInstance = lInstance + 1
If lInstance >= lItemIndex Then
'MsgBox UCase$(oThisNode.Text)
'Found matching item
TreeViewFindNode = n
Exit For
End If
End If
Next
2. When a node is selected in code it is not highlighted - if I tap the treeview anywhere the selected node is highlighted ... I don't know how to get the focus on the treeview - can I simulate a tap?

Many thanks for any help - I am a beginner and welcome all help and advice!
Rob
 
Last edited:

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
1. When I loop thru the nodes to search for a node using the following code I only see the parent nodes whereas a nodecount gives 38 I have 3 parents, 6 children and 29 grandchildren.

I dont think your problem is specific to CF.

At the moment, you arent recursing all the children of each node, which is why you are only seeing the parent nodes.

VB.NET:
        Dim nodes As TreeNodeCollection = TreeView1.Nodes
        For Each n As TreeNode In nodes
            RecurseNode(n)
        Next

    Private Sub RecurseNode(ByVal treeNode As TreeNode)
        ' Print each node recursively. 
        MessageBox.Show(treeNode.Text) 'this node
        For Each tn As TreeNode In treeNode.Nodes
            RecurseNode(tn) 'now recurse all the children of this node
        Next
    End Sub

2. When a node is selected in code it is not highlighted - if I tap the treeview anywhere the selected node is highlighted ... I don't know how to get the focus on the treeview - can I simulate a tap?

Use the SelectedNode property :-

VB.NET:
TreeView1.SelectedNode = TreeView1.Nodes(5)

Slightly off-topic, you should consider :-

1. Set Option Strict On
2. Is there a specific reason why you are using legacy VB6 functions? For instance,
VB.NET:
If InStr(UCase$(n.Text), sFindItem) > 0

is now

VB.NET:
If n.Text.ToUpper.Contains (sFindItem)

It may not seem much different, but the Intellisense in VB.NET is far more powerful than the VB6 IDE.
 

robhermans

Member
Joined
Sep 26, 2009
Messages
6
Programming Experience
10+
Thanks InertiaM

I see you're from the UK - I'm in Philly - but originally from Hornsey,N.8. - but I waffle! ... Thanks for your response - curiously (or not!) the code did work in VB6 - I am old VB6er and am having THE worst job moving to VS ... I will give your suggestions a try - Do you or anyone else have any ideas on moving over from VB6 -> VS? ... I have bought countless books - but when you know how to do something one way, and it's so darned convuluted the new way, you tend to stay where you were ... I know, excuses!!
Thanks again!
Rob
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I went from VB6 to .NET - I tried it once, hated it and went back to VB6. When it was obvious that I REALLY had to change, I decided the best way was not to try and convert my projects over, but to write them again from scratch. I knew all the pitfalls that would come from that, but decided it was (for me, anyway) the only way to learn.

Here are my top tips :-

1. Remove the reference to "Microsoft.VisualBasic" - you'll never learn the new way if you keep using legacy functions.

2. Turn Option Strict On - it will make you think differently :)

3. Learn about using Regions in code. It makes reading your code so much easier.

4. If you dont already know about them, learn about List (of T), Queue (of T), BackgroundWorker, and how to build your own custom Class.

There are more, but I think they are the top ones. It will hurt having to change, but you'll write better code in the long run - trust me :)
 

robhermans

Member
Joined
Sep 26, 2009
Messages
6
Programming Experience
10+
Thanks

Thanks for the suggestions ... Where are you in the UK - curious?? My resistance is unbelievable, even for me ... the whole OOP thing has been foreign from the getgo ... and I am SO GOOD at writing unending embeddeded VB6 LOOPS and FORs and IF/ENDIFs ... and I still make a good living at it ... Anyway, I really will try your suggestions ... and once again Thanks ...
Rob
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I'm actually down in the garden of England, sunny Kent :)

The only part of VB.NET that I have found to be more long-winded than VB6 is printing. It is easier and gives better results, but takes far more keystrokes.

Come on Rob, embrace the change - you know it makes sense :D
 

robhermans

Member
Joined
Sep 26, 2009
Messages
6
Programming Experience
10+
Intellisense does not show .Contains

I was recommended to not use legacy vb - and I agree - it's a good idea. But programming using the Compact framework ...

For example "If n.Text.ToUpper.Contains (sFindItem)"

But when I code

If n.Text.ToUpper.
I enter the dot but intellisense does not offer any options such as "contains" I am guessing either I am not setting something correctly or maybe the compact framework does not support? Any help appreciated. Thanks
Rob

If n.Text.ToUpper.Contains (sFindItem)
 
Top Bottom