Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将项从Datagridview控件拖动到TreeView控件中_Vb.net_Datagridview - Fatal编程技术网

Vb.net 将项从Datagridview控件拖动到TreeView控件中

Vb.net 将项从Datagridview控件拖动到TreeView控件中,vb.net,datagridview,Vb.net,Datagridview,我有一个DataGridView,它有行,但它没有使用完整的行选择。我在DataGridView中选择项的方式只是通过该特定行的列的单个值。例如DataGridView1.Rowse.RowIndex.Cellse.ColumnIndex.Value.ToString 我正在尝试找出如何使它成为这样,当我单击第1行的第一列值并将其拖动到TreeView控件时,它将为从第1行第1列拖动的任何值创建节点。在进行更多挖掘后,我能够找到我要查找的内容。我知道stack overflow不是来为我写程序的

我有一个DataGridView,它有行,但它没有使用完整的行选择。我在DataGridView中选择项的方式只是通过该特定行的列的单个值。例如DataGridView1.Rowse.RowIndex.Cellse.ColumnIndex.Value.ToString


我正在尝试找出如何使它成为这样,当我单击第1行的第一列值并将其拖动到TreeView控件时,它将为从第1行第1列拖动的任何值创建节点。在进行更多挖掘后,我能够找到我要查找的内容。我知道stack overflow不是来为我写程序的,但是stack overflow是建立在帮助将人们推向正确方向而不是拖拉的概念中的

下面是我找到并修改的代码,以使其正常工作

因为我的TreeView是动态构建的,所以我必须手动设置addhandler。通常,如果您已经有了一个TreeView,您可以使用datagridview拖动所示的句柄

   AddHandler DirTree.DragEnter, AddressOf treeView1_DragEnter
    AddHandler DirTree.DragDrop, AddressOf treeView1_DragDrop


Private dragedItemText As String
    Private Sub treeView1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
        Dim pt As Point
        Dim destinationNode As TreeNode
        pt = DirTree.PointToClient(New Point(e.X, e.Y))
        destinationNode = DirTree.GetNodeAt(pt)
        Dim dragedNode As New TreeNode()
        dragedNode.Text = dragedItemText
        lblTitle.Text = dragedItemText

        destinationNode.Nodes.Add(dragedNode)
        dragedItemText = ""
    End Sub

    Private Sub treeView1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
        e.Effect = DragDropEffects.Copy
    End Sub

    Private Sub dataGridView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles DataGridView1.MouseDown
        If e.Button = MouseButtons.Left Then

            dragedItemText = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value.ToString 
          'Cells(0) for first column
            DataGridView1.DoDragDrop(dragedItemText, DragDropEffects.Copy)
        End If
    End Sub

对于初学者,请发布相关代码以及您遇到的问题,我们将很乐意提供帮助。我该怎么做呢?我们不是来为你们编程的,而是来帮助解决一个具体问题的。