Connecting Tech Pros Worldwide Forums | Help | Site Map

Drag & Drop into DataGrid

akashazad's Avatar
Member
 
Join Date: Sep 2007
Location: Aund,Pune
Posts: 36
#1: 4 Weeks Ago
Dear Friends
In my Project I want to Drag the text of the Text Box into any Particular cell of the DataGrid which ever user wants to,

but my problem is I am not able to find the Coordinates of the cell cell in which user will drop the text and hence not able to put the text into desired Cell.

Code snippet below shows the code in the Dragdrop event of the dataGrid

Dim sText As String = ""

Dim nrow As Integer = 'Need to get this rowIndex
Dim nCol As Integer = 'Need to get this ColIndex
Dim txt As TextBox = DirectCast(e.Data.GetData(GetType(TextBox)), TextBox)
sText = txt.Text
DataGridView1.Rows(nrow).Cells(ncol).Value = sText


Some body pl help its urgent

MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#2: 4 Weeks Ago

re: Drag & Drop into DataGrid


Hi,

You can add
Expand|Select|Wrap|Line Numbers
  1. (ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
in the header of your sub. The System.Windows.Forms.DataGridViewCellEventArgs contain RowIndex and ColumnIndex. You can use those.

Steven
akashazad's Avatar
Member
 
Join Date: Sep 2007
Location: Aund,Pune
Posts: 36
#3: 4 Weeks Ago

re: Drag & Drop into DataGrid


Hi MrMancunian

Thanx for the reply,but I am unable to understand where do you exactly want me to add this line .

Please explain with a example if possible.
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#4: 4 Weeks Ago

re: Drag & Drop into DataGrid


Sorry, I was mistaken. You can use something like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DataGridView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
  2.   Dim ht As DataGridView.HitTestInfo = DataGridview1.HitTest(DataGridView1.PointToClient( new Point(e.X, e.Y)))
  3.   MsgBox(ht.ColumnIndex & ", " & ht.RowIndex)
  4. End Sub
Steven
akashazad's Avatar
Member
 
Join Date: Sep 2007
Location: Aund,Pune
Posts: 36
#5: 4 Weeks Ago

re: Drag & Drop into DataGrid


Dear MrMancunian

Thanx for the Reply,it worked
you saved my life man.
Thanx once again
Reply