Drag & Drop into DataGrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akashazad
    New Member
    • Sep 2007
    • 38

    Drag & Drop into DataGrid

    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.Da ta.GetData(GetT ype(TextBox)), TextBox)
    sText = txt.Text
    DataGridView1.R ows(nrow).Cells (ncol).Value = sText


    Some body pl help its urgent
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Hi,

    You can add
    Code:
    (ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    in the header of your sub. The System.Windows. Forms.DataGridV iewCellEventArg s contain RowIndex and ColumnIndex. You can use those.

    Steven

    Comment

    • akashazad
      New Member
      • Sep 2007
      • 38

      #3
      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.

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

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

        Code:
        Private Sub DataGridView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
          Dim ht As DataGridView.HitTestInfo = DataGridview1.HitTest(DataGridView1.PointToClient( new Point(e.X, e.Y)))
          MsgBox(ht.ColumnIndex & ", " & ht.RowIndex)
        End Sub
        Steven
        Last edited by MrMancunian; Oct 28 '09, 03:02 PM. Reason: Typo

        Comment

        • akashazad
          New Member
          • Sep 2007
          • 38

          #5
          Dear MrMancunian

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

          Comment

          Working...