Hi chatelain,
Thanks a lot. your code solved my problem and now I solve urs :)
To get the click event of the button in the cell (that u selects), please add declare the following italic line (pointed by arrow) line as
--->
Dim ButtonControl As New Button
ButtonControl.Text = "Path"
ButtonControl.Width = 50
ButtonControl.Cursor = System.Windows.Forms.Cursors.Arrow
ButtonControl.Dock = DockStyle.Right
ButtonControl.SendToBack()
Dim CurrentColumn As Int16 = myDataGrid.CurrentCell.ColumnNumber
Dim DataGridTextBox = CType(myDataGrid.TableStyles(0).GridColumnStyles(5 ), DataGridTextBoxColumn)
DataGridTextBox.TextBox.Controls.Add(ButtonControl )
ButtonControl.BringToFront()
as a public member of the class, as
Public WithEvents ButtonControl As New Button
Now add ur handler as
Private Sub ButtonControl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonControl.Click
MsgBox("test")
End Sub
Enjoy :)
Regards
Ok a couple things I've got going: On the DataGrid1_CurrentCellChanged I add a button control to the datagridtextbox. This occurs when a mouse click happens inside the cell or the cursor enters the cell. I'm trying to figure out how to capture the Enter key so to run the buttoncontrol click function. I can get this to work when the datagrid only is activated (by clicking on the whitespace of the grid) but of course it won't work when the cursor is activated. I either need to capture the keypress event while a cell is activated so it can run the button control function or after I add the button control to the datagridtextbox somehow select the whitespace so the datagrid.keypress event will run.
FYI - I'm not sure how to implement this solution or if it will work for what I need: Override ProcessCmdKey
Code:
- Public Sub FormatCellControl()
-
'Create the button control to be added and set its properties
-
ButtonControl = New Button
-
ButtonControl.Cursor = System.Windows.Forms.Cursors.Arrow
-
ButtonControl.Dock = DockStyle.Fill
-
ButtonControl.SendToBack()
-
Dim CurrentColumn As Int16 = DataGrid1.CurrentCell.ColumnNumber
-
Select Case CurrentColumn
-
Case 2
-
DatagridTextBox = CType(DataGrid1.TableStyles(0).GridColumnStyles(2), DataGridTextBoxColumn)
-
DatagridTextBox.TextBox.Controls.Add(ButtonControl)
-
ButtonControl.BringToFront()
-
End Sub
-
-
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
-
FormatCellControl()
-
End Sub
-
Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
-
If Datagrid1.CurrentCell.ColumnNumber = 2 Then
-
ButtonClick()
-
End if
-
End Sub
-
Private Sub ButtonClick()
-
Dim ChildFrm As New Form2()
-
ChildFrm.ShowDialog()
-
End Sub