Showing posts with label gui. Show all posts
Showing posts with label gui. Show all posts

Tuesday, June 12, 2007

Trees... Trees... & MORE Trees...

Source: vbCity

The Basics of a TreeView


You'll be familiar with the look and feel of a treeview from the Windows Explorer. Its name of course refers to a regular tree, that has one trunk and many branches and where each branch can have smaller branches. The stem is the treeview object itself, the "branches" are called nodes. The main difference between a branch and a node is that the thickness of a node doesn't need to decrease; on the contrary: the 'ends' can easily be the thickest part of the whole: that is contain the most items.

In principle the number of items and childnodes is unlimited (read: a number you will not easily reach wink ) Each node can contain an item collection (child nodes) and has a parent. Using the item collection and the parent property, you can go through all branches. If you go 'down', you will know you have reached the end when there are no more childitems (GetNodeCount = 0) and you have reached a toplevel node when the parent is the listview object itself.

Populating the treeview during runtime is very easy: just go to the Collection property and press the "..." button. You can play around with the possibilities. To populate during runtime:

Code:
Dim N As TreeNode

'Method 1: straightforward adding of nodes
With Me.TreeView1.Nodes
'add text
.Add("AddByText")
'since with..end with is used: read TreeView1.Nodes.Add ....

'every add method returns the newly created node. You can use
'this concept set the result to a variable or to directly add
'a childnode:
.Add("AddByText2").Nodes.Add("ChildOfAddByText")

'this, you can take as far as you want
.Add("AddByText3").Nodes.Add("ChildOfAddByText").Nodes.Add("Another child")

'--
N = .Add("AddByText, Attach To Variable")
N.Nodes.Add("Child one")
N.Nodes.Add("Child two")
' --
With .Add("AddByText Use WithTo Add ChildNodes").Nodes
.Add("Child 1")
.Add("Child 2")
.Add("Child 3").Nodes.Add("Subchild 1")
End With
End With

'for clarity, from here on, the treeview1 name will be added.
'In everyday use, you'll probably find the use of with..end with
'a lot easier (I know I do..)

'Method 2: adding by node
'Like virtually every .Net method you can directly assign an object:
Me.TreeView1.Nodes.Add(New TreeNode("AddByNode"))

'check out the overloading possibilities of using New()
'Another advantage of this method is that you can add a complete branch.
'(N is already declared as TreeNode above)
N = New TreeNode("MainNodeToAdd")
N.Nodes.Add("Child 1")
N.Nodes.Add("Child 2")

'you can for instance add this newly created node to all main branches:
Dim enumNode As TreeNode
For Each enumNode In TreeView1.Nodes
enumNode.Nodes.Add(N.Clone) '<- the clone() method is needed
Next

'Adding will always add the the node at the end of the collection.
'Of course you can also insert at a specified location:
Me.TreeView1.Nodes.Insert(2, New TreeNode("I am inserted at the 3th position"))

'removing is done much in the same way:
N = TreeView1.Nodes.Add("I need to be removed").Nodes.Add("and all children too")
TreeView1.Nodes.Remove(N)

'to clear all branches of any node you can use clear()
N.Nodes.Add("This child you will not see")
N.Nodes.Clear()

'if you use Clear on the treeview nodes itself, you
' would once again have an empty treeview

'once an item has been added, it is part of the item collection in nodes
'this means you can access it by its index
TreeView1.Nodes(0).Text = "I have index 0"

'the behaviour of the treenode can be controlled completely in code.
'you can make it expand
TreeView1.Nodes(0).Expand()

'and retract again
TreeView1.Nodes(0).Collapse()

This is just the basic functionality. There are a lot more properties on a treeview. Some are inherited, some are specific to the treeview object. The sample above should give enough information to create your own treeview. Have fun thumb up!

To finish: an example
Code:

'this example will fill a treeview with the hours of the day.
'the hours will be divided in 15 minute blocks and the blocks
'will be divided in minutes
Sub Example()
Dim N As New TreeNode(), I As Integer, J As Integer

'create a 15 minute block
For I = 0 To 3
With N.Nodes.Add((I * 15).ToString & "-" & ((I + 1) * 15 - 1).ToString)
'add the minutes
For J = 0 To 14
.Nodes.Add((J + I * 15).ToString)
Next
End With
Next

'add the hours and immediately add the blocks to the hours as well
Dim NodeToAdd As TreeNode
For I = 1 To 24
NodeToAdd = N.Clone
NodeToAdd.Text = I.ToString
TreeView1.Nodes.Add(NodeToAdd)
Next
End Sub

'the sub when a time has been chosen
Private Sub ItemChosen(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
Dim N As TreeNode = CType(sender, Windows.Forms.TreeView).SelectedNode
If N.GetNodeCount(False) = 0 Then 'it is 'last' in the line
Dim S As String = N.Text
If S.Length = 1 Then S = S.Insert(0, "0")
S = N.Parent.Parent.Text & ":" & S
MessageBox.Show("You have selected: " & S)
End If
End Sub

Tuesday, May 22, 2007

Heapfuls

Been having an awful lotta new info to absorb into brain. Wahhh. Here's some:

Ping:

A utility to determine whether a specific IP address is accessible. It works by sending a packet to the specified address and waiting for a reply. PING is used primarily to troubleshoot Internet connections. There are many freeware and shareware Ping utilities available for personal computers.

It is often believed that "Ping" is an abbreviation for Packet Internet Groper, but Ping's author has stated that the names comes from the sound that a sonar makes.

Source: Webopedia


Web Service:

The term Web services describes a standardized way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available. Used primarily as a means for businesses to communicate with each other and with clients, Web services allow organizations to communicate data without intimate knowledge of each other's IT systems behind the firewall.
Unlike traditional client/server models, such as a Web server/Web page system, Web services do not provide the user with a GUI. Web services instead share business logic, data and processes through a programmatic interface across a network. The applications interface, not the users. Developers can then add the Web service to a GUI (such as a Web page or an executable program) to offer specific functionality to users.

Web services allow different applications from different sources to communicate with each other without time-consuming custom coding, and because all communication is in XML, Web services are not tied to any one operating system or programming language. For example, Java can talk with Perl, Windows applications can talk with UNIX applications.

Web services do not require the use of browsers or HTML.

Web services are sometimes called application services.

Source: Webopedia


Serialisation:
http://aspalliance.com/983_Introducing_Serialization_in_NET