CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, April 10, 2007

How to use TreeView Control in .NET 1.1

How to use IE Treeview control in asp.net 1.1 application
First of all you need IE webcontrols. Download form msdn site and the compile it according to given instruction. Some problem is come because the csc.exe given in the build.bat is not found. You search it in winnt directory usually you found it in the x:\winnt\dotnetframework\10.11\csc.exe edit build.bat file and paste this path with the csc.exe then save it and run it a dll file created. Create a new asp.net project paste this file in bin directory. Go to add remove controls on control panel and add this dll. You found four new conrols in the control panel .drag treeview control on the webform.
Consider my application containing two tables known as product master and product detail both have one to many relationship . Product master table contain two fields. Product_id as pamary key and product_name while product detail table has three field. Product_id as forgin key from product master table , product_detail_id and product_detail_name . have some one so I used to displace this master detail relationship as below
Public Sub populateTreeview()
Dim defaultStyle As String ‘ show the drew node text accorind to color fonts and background ‘color by default
Dim HoverStyle As String ‘ set the font color background color or similar properties when mouse ‘come over it the treeview nodes text
Dim selectedStyle As String ‘set the font color background color or similar properties when mouse ‘click over it the treeview nodes’ text
defaultStyle = "color:Green;font-size:12pt;font-weight:bold;background:WHITE"
' defaultStyle = "background:White;color:Green;font-size:10pt;font-weight:bold"
HoverStyle = "color:Red;font-name:Arial; font-weight:bold;background:WHITE"
selectedStyle = "color:RED;font-name:Arial;font-weight:bold-italic;background:WHITE"
Dim selectedCollection, defaultcollection, HoverCssCollection As CssCollection
selectedCollection = New CssCollection(selectedStyle)
defaultcollection = New CssCollection(defaultStyle)
HoverCssCollection = New CssCollection(HoverStyle)

Dim s As String
' s = "@color:black;background:white; border:black thin solid;"
' HoverCssCollection = New CssCollection(s)
Dim query As String
Dim objDataset As New DataSet

Dim objconnection as sqlclient .sqlConnection
Connection= new oledb.oleDbConnection(“ Connection String according to you system “)
query = "select Techno_id, Techno_services_name from techno_services_master"
objDataAdapter = New OleDb.OleDbDataAdapter
' objDataSet = New DataSet
objDataAdapter.SelectCommand = New OleDb.OleDbCommand(query, objConnection)
objDataAdapter.Fill(objDataset, tableName)

query = "select techno_id,Techno_services_Detail_no,Techno_services_detail_name from Techno_services_detail"
objdb.getDataset(objDataset, query, "tblTechnoDetail")
objDataset.Relations.Add("ParentChild", objDataset.Tables("tblTechnoMaster").Columns("Techno_id"), objDataset.Tables("tblTechnoDetail").Columns("Techno_id"))
Dim nodeSupp, nodeProd As TreeNode
Dim rowSupp, rowProd As DataRow


For Each rowProdMaster In objDataset.Tables("tblTechnoMaster").Rows
nodeProdMaster = New TreeNode

nodeProdMaster.DefaultStyle = defaultcollection
nodeProdMaster.HoverStyle = HoverCssCollection
nodeProdMaster.SelectedStyle = selectedCollection
nodeProdMaster.ImageUrl = "Imagie/image001.GIF"
nodeProdMaster.Text = rowSupp("Techno_services_name")
nodeProdMaster.ID = rowSupp("Techno_id")
TreeView1.Nodes.Add(nodeProdMaster)
For Each rowProdDetail In rowProdMaster.GetChildRows("ParentChild")
nodeProdDetail = New TreeNode
nodeProdDetail.DefaultStyle = New CssCollection("color:Black;font-size:12pt;background:WHITE")
nodeProdDetail.Text = rowProd("Techno_services_detail_name")
nodeProd.ID = rowProd("Techno_services_detail_no")
nodeDetailMaster.Nodes.Add(nodeProd)
Next
Next

End Sub

Post a Comment