Tree View Images

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'm creating a messaging application to replace the one already installed on my phone, which will give me some added features that I need.
The initial idea is to use a table to store all intercepted messages with an extra column added to signify whether the message is new or has already been read.
I'd like to use the tree view to show each message i.e.- each column of the table.
So far I'm making good progress, but is it possible to define different images for node1?
I'd like to display an icon to indicate if the message has been read or not, just like already done in most phones.

From the examples and help file it does not look possible, but is there a work-a-round that I could use?

Thanks,
RandomCoder
 

specci48

Well-Known Member
Licensed User
Longtime User
Hi RandomCoder,

I am just before finishing a small todo-tree application so I came up this question some time ago. As I was not able to select individual images for each node, I added a small character to the beginning of the node text, indicating that this node has additional information.

It looks something like this (see attachment). Maybe you use this as an indication for read/unread messages.


specci48

@Erel: You can add this missing feature to the wishlist for future updates... ;)
 

Attachments

  • Marker.jpg
    Marker.jpg
    3.8 KB · Views: 166

RandomCoder

Well-Known Member
Licensed User
Longtime User
I hadn't thought of that but it's exactly the kind of work-a-round I was after.
Thanks for sharing it with us.

Erel, if we could have individual images for each node some time in a future release then that would be better still ;)

Thanks,
RandomCoder
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
TreeView supports different images for different nodes.
For example:
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    tree.New1("form1",10,10,200,300)
    node.New1
    tree.ImageMode = true
    tree.AddImage1(AppPath & "\smiley.gif")
    tree.AddImage1(AppPath & "\folder.bmp")
    tree.AddImage1(AppPath & "\openfolder.bmp")
    node.Value = tree.AddNewNode("first")
    node.ImageIndex = 0
    node.SelectedImageIndex = 0
    node.Value = tree.AddNewNode("second")
    node.ImageIndex = 1
    node.SelectedImageIndex = 1
    node.Value = tree.AddNewNode("third")
    node.ImageIndex = 2
    node.SelectedImageIndex = 2
End Sub
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Erel, this is great news, I've just played with the code and it works :sign0060:

What I hadn't realised from the "Folder Chooser" example (which others can find here... http://www.b4x.com/forum/showthread.php?t=582&highlight=folderchooser Post #4) was that you can redefine the node.
I had misunderstood that this would add another level to the tree, but that was because in the folder chooser you have actually set two nodes, Node1.New1 and Node2.New1.
I think that the penny has finaly dropped for me :signOops:

Thanks once again for your support.

Regards,
RandomCoder
 

specci48

Well-Known Member
Licensed User
Longtime User
Wow... :SHOCKED: ... I didn't realize this possibility yet.

This feature drives my current project into a very nice different direction... :sign0060:


specci48
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Why won't this work now???

After your helpful post #4 I thought that I'd grasped how to make the tree control work the way I wanted but for some reason I'm still having problems :confused:

This is the snippet of code I'm struggling with...
B4X:
Sub UpdateInbox
 TreeViewInbox.RemoveAllNodes
 For MSG = 0 To TBLSMSInbox.RowCount-1
  If TblSMSInbox.Cell( "READ" , MSG ) = False Then
   TreeViewNode1.Value = TreeViewInbox.AddNewNode( TblSMSInbox.Cell( "FROM" , MSG ) & "  --  " & Time( TblSMSInbox.Cell( "DATE" , MSG ) ) & " , " & Date( TblSMSInbox.Cell( "DATE" , MSG ) ) )
   TreeViewNode2.Value = TreeViewNode1.AddNewNode( TblSMSInbox.Cell( "BODY" , MSG ) )
   TreeViewInbox.ImageIndex = 0
   TreeViewInbox.SelectedImageIndex = 0
  Else
   TreeViewNode1.Value = TreeViewInbox.AddNewNode( TblSMSInbox.Cell( "FROM" , MSG ) & "  --  " & Time( TblSMSInbox.Cell( "DATE" , MSG ) ) & " , " & Date( TblSMSInbox.Cell( "DATE" , MSG ) ) )
   TreeViewNode2.Value = TreeViewNode1.AddNewNode( TblSMSInbox.Cell( "BODY" , MSG ) )
   TreeViewInbox.ImageIndex = 1
   TreeViewInbox.SelectedImageIndex = 1
  End If
 Next
 TreeViewInbox.ExpandAll
End Sub

When the READ column is True, then the tree view should display image 1, but it doesn't, it continues to show image 0.
I've checked that the Else block of code is being used my inserting a MsgBox in there and I've double checked that image 1 is working by changing the other image 0 commands.
For some reason I just cannot get the tree view to loop through my table and display an image the depicts whether the message has been read or not.
Am I just being really thick today??? :sign0013:

Regards,
RandomCoder
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should change the nodes images not the treeview images.
try this:
B4X:
Sub UpdateInbox
 TreeViewInbox.RemoveAllNodes
 For MSG = 0 To TBLSMSInbox.RowCount-1
  If TblSMSInbox.Cell( "READ" , MSG ) = False Then
   TreeViewNode1.Value = TreeViewInbox.AddNewNode( TblSMSInbox.Cell( "FROM" , MSG ) & "  --  " & Time( TblSMSInbox.Cell( "DATE" , MSG ) ) & " , " & Date( TblSMSInbox.Cell( "DATE" , MSG ) ) )
   TreeViewNode2.Value = TreeViewNode1.AddNewNode( TblSMSInbox.Cell( "BODY" , MSG ) )
   TreeViewNode1.ImageIndex = 0
   TreeViewNode1.SelectedImageIndex = 0
  Else
   TreeViewNode1.Value = TreeViewInbox.AddNewNode( TblSMSInbox.Cell( "FROM" , MSG ) & "  --  " & Time( TblSMSInbox.Cell( "DATE" , MSG ) ) & " , " & Date( TblSMSInbox.Cell( "DATE" , MSG ) ) )
   TreeViewNode2.Value = TreeViewNode1.AddNewNode( TblSMSInbox.Cell( "BODY" , MSG ) )
   TreeViewNode1.ImageIndex = 1
   TreeViewNode1.SelectedImageIndex = 1
  End If
 Next
 TreeViewInbox.ExpandAll
End Sub
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
:sign0013:

After loads of attempts at getting this working I just have, but as always, you have beaten me to it :signOops:

Sorry for wasting your time.

Regards,
RandomCoder
 
Top