Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 11th November 2011
Braincode's Avatar
Braincode Braincode is offline
Ceriwis Addicted
 
Join Date: Nov 2011
Posts: 4,638
Rep Power: 21
Braincode mempunyai hidup yang Normal
Default [Need Help] Bagaimana cara mengoptimalkan pembuatan nodes pada treeview? [Vs2005]

Gini gan, gue kan lg membuat program yang kebetulan membutuhkan treeview untuk pengelompokan kategorinya.

Saat ini sih sudah selesai dikerjakan prosedur cetak treeviewnya.

Namun gue rasa ada yg 'salah' (baca: tidak efisien?) dalam genarate nodes ini.

Setiap kali prosedur ini dipanggil, membutuhkan waktu yg cukup lama mnrt gue sendiri (dari 47 data categori, membutuhkan waktu kurang lebih 3-4detik untuk genarate nodesnya)



spesifikasi program: vs2005 + access




Spoiler for Struktur tabel:






Nama tabel = Master_Category

Jumlah field = 2

Field I = Category

*berupa primary key, berisikan nama-nama kategori yg ada

Field II = Category_Location

*berisikan "parent" dari kategori tersebut



contoh:

computer # root

harddisk # computer

SATA # harddisk

IDE # harddisk

dst...











*genaratenodes ini adalah function utamanya, jadi tinggal memanggil function ini untuk menghasilkan treeview yg sudah berisikan data semua kategori

pseudocode: kosongkan treeview, cari dan cetak semua category yg mrpkn root berdasar DB, cari semua subcategory-nya


Code:

Private Sub GenarateNodes()

TreeView_Category.Nodes.Clear()

ExeQuery("Select Category as 'Category', Category_Location From MASTER_CATEGORY Where Category_Location = '- ROOT LEVEL -' Order by Category")
SetTable("MASTER_CATEGORY")
DataGridViewX_ChildNodes.DataSource = DataSet.Tables("MASTER_CATEGORY")

If TableRowsCount("MASTER_CATEGORY") 0 Then
Dim RootCount As Integer = TableRowsCount("MASTER_CATEGORY")
For i As Integer = 0 To RootCount - 1
Dim NewNode As TreeNode
NewNode = TreeView_Category.Nodes.Add(DataGridViewX_ChildNod es.Rows(i).Cells(0).Value)
NewNode.Name = DataGridViewX_ChildNodes.Rows(i).Cells(0).Value
NewNode.ForeColor = Color.Blue
Next
End If

'untuk setiap root category, cari subcategorynya
Dim n As TreeNode
For Each n In TreeView_Category.Nodes
CreateNodes(n)
Next

End Sub



pseudocode: untuk setiap category, cari dan cetak subcategorynya, jika masih punya subcategory maka telusuri terus sampai akhir


Code:

Private Sub CreateNodes(ByVal n As TreeNode)

ExeQuery("Select Category as 'Category', Category_Location From MASTER_CATEGORY Where Category_Location = '" & n.Name & "' Order by Category")
SetTable("MASTER_CATEGORY")
DataGridViewX_ChildNodes.DataSource = DataSet.Tables("MASTER_CATEGORY")

If TableRowsCount("MASTER_CATEGORY") 0 Then
For i As Integer = 0 To TableRowsCount("MASTER_CATEGORY") - 1
Dim NewNode As TreeNode
NewNode = n.Nodes.Add(DataGridViewX_ChildNodes.Rows(i).Cells (0).Value)
NewNode.Name = DataGridViewX_ChildNodes.Rows(i).Cells(0).Value
NewNode.ForeColor = Color.Blue
Next
End If

'untuk recursivenya (telusuri sampai leaf)
Dim aNode As TreeNode
For Each aNode In n.Nodes
CreateNodes(aNode)
Next

End Sub

Kira-kira bagian mana yg 'salah' dan bisa diefisienkan?

thanks gan

</div>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Terkait
Thread Thread Starter Forum Replies Last Post
Cara Instal WordPress Pada Webfarm Web Nodes Liayulia Komputer & Teknologi 0 6th November 2013 09:23 AM

 


All times are GMT +7. The time now is 11:48 PM.