/ / विशिष्ट स्थान पर एक ट्रीव्यू सेट करें - vb.net, ट्रीव्यू

किसी विशिष्ट स्थान पर ट्रीव्यू सेट करें - vb.net, ट्रीव्यू

मेरे पास C में एक फ़ोल्डर है: वह ड्राइव जो मैं अपने फॉर्म लोड होते ही एक्सेस करना चाहता हूं। मैं प्रत्येक नोड को खोलने के माध्यम से स्क्रॉल नहीं करना चाहता हूं। मैं एक ट्रीव्यू का उपयोग करना चाहता हूं क्योंकि मुझे पता है कि इन में बहुत सारी सुविधाओं का उपयोग कैसे करना है और यह मेरे उद्देश्य के अनुरूप होगा।

मैं आपको एक बुनियादी फ़ाइल संरचना का उपयोग करके जो मैं चाहता हूं उसका एक उदाहरण दूंगा: C: UsersuserDocumentsVisual Studio 2010Projects

यदि मुझे पूरे ट्रीव्यू के माध्यम से यह करना है तो मुझे एक्सेस करने के लिए कई नोड्स लेने होंगे। मैं चाहता हूं कि मेरा ट्रीव्यू शुरू हो जाए, इसलिए मुख्य नोड होना चाहिए परियोजनाओं

मैं ऐसा कैसे कर पाऊंगा?

उत्तर:

उत्तर № 1 के लिए 1

यहाँ एक उदाहरण है जो मानता है नाम नोड फ़ोल्डर का पूर्ण पथ है:

Protected Overrides Sub OnLoad(e As EventArgs)
Dim name As String = "c:usersblairgdocumentsvisual studio 2010projects"

Dim testNode As New TreeNode("Projects")
testNode.Name = name
TreeView1.Nodes.Add(testNode)

Dim node() As TreeNode = TreeView1.Nodes.Find(name, True)
If node.Count = 1 Then
TreeView1.SelectedNode = node(0)
End If

MyBase.OnLoad(e)
End Sub

जवाब के लिए 0 № 2

मुझे यकीन है कि ऊपर दिया गया जवाब काम करेगा। हालाँकि मैं इसे करने में सफल रहा:

        Dim backupfolder As String = netpath & "MANUFPC BACKUP PROCESS" & site & "" & factory & "" & line & "" & pc

Dim mRootNode As New TreeNode
mRootNode.Text = pc
mRootNode.Tag = backupfolder
mRootNode.Nodes.Add("*DUMMY*")
"adds plus icon to allow extension
backupFolderDirectory.Nodes.Add(mRootNode)

फिर दो अन्य कार्य:

Private Sub TreeView1_BeforeCollapse(ByVal sender As Object, ByVal e As TreeViewCancelEventArgs) Handles backupFolderDirectory.BeforeCollapse
" clear the node that is being collapsed
e.Node.Nodes.Clear()
" add a dummy TreeNode to the node being collapsed so it is expandable
e.Node.Nodes.Add("*DUMMY*")
End Sub

Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As TreeViewCancelEventArgs) Handles backupFolderDirectory.BeforeExpand
" clear the expanding node so we can re-populate it, or else we end up with duplicate nodes
e.Node.Nodes.Clear()

" get the directory representing this node
Dim mNodeDirectory As DirectoryInfo
mNodeDirectory = New DirectoryInfo(e.Node.Tag.ToString)
" add each subdirectory from the file system to the expanding node as a child node
Try
For Each mDirectory As DirectoryInfo In mNodeDirectory.GetDirectories
" declare a child TreeNode for the next subdirectory
Dim mDirectoryNode As New TreeNode
Dim mystring(1) As String
mystring(0) = mDirectory.FullName
mystring(1) = "directory"
" store the full path to this directory in the child TreeNode"s Tag property
mDirectoryNode.Tag = mystring(0)
" set the child TreeNodes"s display text
mDirectoryNode.Text = mDirectory.Name
" add a dummy TreeNode to this child TreeNode to make it expandable
mDirectoryNode.Nodes.Add("*DUMMY*")
" add this child TreeNode to the expanding TreeNode
e.Node.Nodes.Add(mDirectoryNode)
Next

For Each mFiles As FileInfo In mNodeDirectory.GetFiles
" declare a child TreeNode for the next subdirectory
Dim mFileNode As New TreeNode
Dim mystring(1) As String
mystring(0) = mFiles.FullName
mystring(1) = "file"
" store the full path to this directory in the child TreeNode"s Tag property
mFileNode.Tag = mystring(0)
" set the child TreeNodes"s display text
mFileNode.Text = mFiles.Name
" add this child TreeNode to the expanding TreeNode
e.Node.Nodes.Add(mFileNode)
Next

Catch ex As IOException
"sets up 2 different exceptions then the last one catches other exceptions that could be made from adding folder/files etc
e.Node.Remove()
MsgBox("Device/Folder not accessible", MsgBoxStyle.OkOnly, "Device not Ready")
Catch exc As NullReferenceException
e.Node.Remove()
MsgBox("Sorry this File/Folder can not be added", MsgBoxStyle.OkOnly, "Sorry")
Catch exce As Exception
e.Node.Remove()
MsgBox("Device/Folder not accessible", MsgBoxStyle.OkOnly, "Device not Ready")
End Try
End Sub