how to find the cursor and mouse pointer on datagridview cell

prashantsvl

Member
Joined
Jul 24, 2008
Messages
10
Programming Experience
Beginner
hello

dear to alll

i am actualy working all the editing the datagrid viewcell and i want to
add new string on buttion click i cell

suppose string= "hello"
and if i click on in between the "he|llo"

and i click the buttion having the text "A" then it must have to add in the
string .

so resultant string ="heAll0"
 
VB.NET:
Private selectionStart As Integer

Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
    Dim c As Control = Me.DataGridView1.EditingControl
    If c IsNot Nothing AndAlso TypeOf c Is TextBox Then
        selectionStart = CType(c, TextBox).SelectionStart
    End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim text As String = CStr(Me.DataGridView1.CurrentCell.Value)
    Me.DataGridView1.CurrentCell.Value = text.Insert(selectionStart, "A")
End Sub
 
Back
Top