PDA

View Full Version : کار با نمودار درختی و دیتابیس



bagion
دوشنبه 09 دی 1392, 22:13 عصر
با سلام خدمت عزیزان
این برنامه اطلاعات دیتابیس را بصورت نمودار درختی نشان می دهد.
حالا من میخوام دکمه ای باشه که وقتی فشرده شد، یکی از این سطرها انتخاب بشه(یکی از پیام های 0 1 2 3 4 5 رو نشون بده ) آیا امکان داره؟

دانلود (http://www.uploadefile.com/file/5814/tree-view.rar.html)

فرید نجفلو
چهارشنبه 11 دی 1392, 21:28 عصر
سلام کد شما رو تغییراتی دادم امیدوارم منظورتون همین باشه (+تعدادی اصلاح اضافه) Imports System.Data Imports System.Data.OleDb Public Class Form1 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim objConnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=setting.mdb;jet oledb:database password=me602") Dim ds As New DataSet 'ds.Clear() 'Dim bs As New BindingSource Dim dta As New OleDbDataAdapter("select * from personel", objConnection) If objConnection.State = ConnectionState.Closed Then objConnection.Open() dta.Fill(ds, "personel") '***** اصلاح شد **** 'همیشه اتصال چک کرده و ببندید!!! If objConnection.State ConnectionState.Closed Then objConnection.Close() ''''''colum 0 Dim c As TreeNode = tw1.Nodes.Add(ds.Tables("personel").Columns(1).ColumnName) 'ezafe kardane sotune aval For Each aRow As DataRow In ds.Tables("personel").Rows Dim nd As TreeNode = c.Nodes.Add(CStr(aRow(1))) 'ezafe kardane satre aval nd.Tag = aRow '****اصلاح شد***** Next ''''''colum 1 Button4.Enabled = False End Sub Private Sub tw1_NodeMouseClick(sender As System.Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tw1.NodeMouseClick '***** اصلاح شد **** If TypeOf e.Node.Tag Is DataRow Then MsgBox(CType(e.Node.Tag, DataRow)(0)) End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim ID As Integer = 3 'نحوه گرفتن این از کاربر با خودت Dim nd = GetNodeByID(ID) If nd IsNot Nothing Then tw1.SelectedNode = nd Catch ex As Exception End Try End Sub ''' ''' جسنجوی گره ی با یک آی دی خاص ''' Private Function GetNodeByID(ID As Integer, Optional Nodes As TreeNodeCollection = Nothing) As TreeNode Try If Nodes Is Nothing Then Nodes = tw1.Nodes For Each aNode As TreeNode In Nodes If TypeOf aNode.Tag Is DataRow Then If CInt(CType(aNode.Tag, DataRow)(0)) = ID Then Return aNode End If End If 'این گره مورد نظر ما نبود 'زیر گره های آن را نیز در صورت وجود جستجو می کنیم If aNode.Nodes.Count > 0 Then Dim SubRes = GetNodeByID(ID, aNode.Nodes) 'حالت بازگشتی If SubRes IsNot Nothing Then Return SubRes End If Next Return Nothing Catch ex As Exception Return Nothing End Try End Function End Class