vb.net樹形列表 vb樹形控件

VB.NET使用Treeview實現(xiàn)貨品樹狀結(jié)構(gòu)分類

你這個要按照數(shù)據(jù)庫的查詢數(shù)據(jù)找出來根節(jié)點(diǎn)。Treeview增加一個節(jié)點(diǎn)。

創(chuàng)新互聯(lián)主營愛輝網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,App定制開發(fā),愛輝h5成都微信小程序搭建,愛輝網(wǎng)站營銷推廣歡迎愛輝等地區(qū)企業(yè)咨詢

然后根據(jù)根節(jié)點(diǎn)找出來所有子節(jié)點(diǎn)。再依次增加TreeView子節(jié)點(diǎn)。

然后逐個子節(jié)點(diǎn)進(jìn)行下一步查詢。再把結(jié)果刷新到TreeView子節(jié)點(diǎn)。

給你說說思路。你肯定會問怎么編程序。

那麻煩你上網(wǎng)到msdn查查Treeview的例子程序,自己學(xué)習(xí)改改看看。

如果你還堅持要別人幫你寫寫數(shù)據(jù)庫查詢的代碼,那你也可以移步msdn查找SQLServer數(shù)據(jù)庫查詢?nèi)绾螆?zhí)行按照關(guān)鍵字查詢。

VB.net怎么制作樹形菜單啊?

你說的“樹形菜單”是指下拉菜單(可以有子菜單)嗎?如果是,VB.net提供了MenuStrip控件,在工具箱里能找到,直接就在對應(yīng)位置打字就可以了,完全是“所見即所得”。

VB.net如何動態(tài)獲取菜單欄中的菜單名并用樹型表示

添加:(先在加一個contextMenu,再它的添加子菜單的click事件編程)

Try

’使TreeView可以被編輯

TreeView1.LabelEdit = True

‘判斷你是不是選定的是不可編輯的節(jié)點(diǎn),我這里工種節(jié)點(diǎn)不可以被編輯,只有工種下級的

各個工種名稱可以被編輯

If Trim(TreeView1.SelectedNode.Text) = "工種" Then

‘添加節(jié)點(diǎn)

AddNode = New TreeNode("請輸入新工種名字")

TreeView1.SelectedNode.Nodes.Add(AddNode)

TreeView1.ExpandAll()

AddNode.BeginEdit()

TreeView1.LabelEdit = True

NodeAdded = True

End If

Catch err As Exception

MsgBox(err.ToString)

End Try

刪除與添加類似,只是如果你的節(jié)點(diǎn)名字從其他處(如數(shù)據(jù)庫)得來,那么你還需要更新數(shù)據(jù)庫

編輯:

Private Sub TreeView1_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.BeforeLabelEdit

TreeView1.LabelEdit = True ‘使可以編輯

AddNode = TreeView1.SelectedNode

End Sub

Private Sub TreeView1_AfterLabelEdit(ByVal sender As Object, ByVal e As System.windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.AfterLabelEdit

Try

‘此時你改完了節(jié)點(diǎn)名字

TreeView1.SelectedNode.EndEdit(True)

If e.Label Is Nothing Then

'do nothing

ElseIf e.Node.Text = "工種" Then ‘工種不能改

e.CancelEdit() = True

‘e.Node.Text ,e.Label.ToString 一個是改前的名字一個是該后的名字,具體哪個對

哪個請查MSDN

ElseIf Trim(e.Node.Text) "工種" And e.Node.Text e.Label.ToString Then

If MsgBox("此操作會導(dǎo)致當(dāng)前工種中的所有人員的工種都被更改,是否確定?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "警告") = MsgBoxResult.Yes Then

。。。。 ‘我的更改

MsgBox("更改成功!", MsgBoxStyle.OKOnly, "提示")

'Call InitTree() ‘有時要重新把treeview初始化一遍,視需求定

End If

End If

Catch err As Exception

MsgBox(err.ToString)

End Try

End Sub

其他:

擋treeview得到焦點(diǎn)時你可以使用ContextMenu,反之ContextMenu禁用

Private Sub TreeView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.GotFocus

TreeView1.ContextMenu = ContextMenu1

End Sub

Private Sub TreeView1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.LostFocus

TreeView1.ContextMenu = Nothing

End Sub

注意:這里沒有在ContextMenu菜單添加“更改”項,而是直接更改:即左鍵單擊節(jié)點(diǎn)表示

選中,再單擊一下就可以編輯了,更改之后單擊他處就完成更改,和你在windows中更改文

件名字相似。

vb.net里樹狀圖怎么畫

很簡單,在頁面上拖個treeview,可以直接給它實裝數(shù)據(jù),運(yùn)行一下,就可展開。

分享標(biāo)題:vb.net樹形列表 vb樹形控件
標(biāo)題鏈接:http://www.muchs.cn/article20/doocgjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、面包屑導(dǎo)航App設(shè)計、網(wǎng)站設(shè)計公司、自適應(yīng)網(wǎng)站、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)