Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

treeview datagrid drag&drop

Status
Not open for further replies.

dannG

Programmer
Jan 9, 2003
26
0
0
RO
Hy,
I want to drag the data stored in a treenode tag(it is text)to a datagrid cell. Do you have any ideas? Some good tutorials? Pls help
thanks
 
Hy,
I have worked somthing, but still it doesnt want to work. The data are trasfered to datagrid but I cannot put it into a cell. I dont' know why. This is my code:
'tw=treeview
'dg=datagrid

Private Sub dg_DragEnter(ByVal sender As Object,_
ByVal e As System.Windows.Forms.DragEventArgs)_
Handles dg.DragEnter
If e.Data().GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub dg_DragDrop(ByVal sender As Object,_
ByVal e As System.Windows.Forms.DragEventArgs) Handles dg.DragDrop
Dim ss As String
If e.Data.GetDataPresent(DataFormats.Text) Then
ss = e.Data.GetData(DataFormats.Text)
'MessageBox.Show(ss)
End If
Dim currRow As DataRow
Dim thisGrid As DataGrid = CType(sender, DataGrid)
Dim myTable As DataTable = CType(thisGrid.DataSource, DataTable)
currRow = myTable.Rows(thisGrid.CurrentCell.RowNumber)
currRow("CodDG") = ss
End Sub
Private Sub tw_MouseDown(ByVal sender As Object,_
ByVal e As System.Windows.Forms.MouseEventArgs) Handles tw.MouseDown
twCodBoli.SelectedNode = twCodBoli.GetNodeAt(e.X, e.Y)
twCodBoli.DoDragDrop(twCodBoli.SelectedNode.Tag.ToString(), DragDropEffects.All)
End Sub

Maybe someone has some ideas. A 2look is allways useful. Thanks
dann
 
You need to find the cell being dropped on by using the DataGrid.HitTestInfo class:
Code:
Dim hti As DataGrid.HitTestInfo = dg.HitTest(dg.PointToClient(New Point (e.X, e.Y)))

If hti.Type = DataGrid.HitTestType.Cell Then

    dg(hti.Row, hti.Column) = e.Data.GetData(DataFormats.Text)

    dg.CurrentCell = New DataGridCell(hti.Row, hti.Column)

End If
 
Thanks SHelton,
Sorry for the delay. I was out in a place with no electric power. Was nice. Thanks for answer.
Your code works fine but still I have a problem. The code works fine only I click before in datagrid. The first column receve the data but I can place the data only the active cell is the second or another one. Do you have more ideas?
thanks again for replay.

I'll post here my resolution for previous problem(is the commented text!), maybe someone need it:

Private Sub dg_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dg.DragDrop
Dim ss As String
If e.Data.GetDataPresent(DataFormats.Text) Then
ss = e.Data.GetData(DataFormats.Text)
'MessageBox.Show(ss)
End If
Dim hti As DataGrid.HitTestInfo = dg.HitTest(dgDiagnostic.PointToClient(New Point(e.X, e.Y)))
If hti.Type = DataGrid.HitTestType.Cell Then
dgDiagnostic(hti.Row, hti.Column) = e.Data.GetData(DataFormats.Text)
dg.CurrentCell = New DataGridCell(hti.Row, hti.Column)
End If
'Dim x As Integer
'Dim y As Integer
'x = dg.CurrentCell.RowNumber
'y = dg.CurrentCell.ColumnNumber
''MessageBox.Show(x.ToString & " " & y.ToString)
'dg.Item(x, 1) = ss
End Sub
dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top