Home Forums WinForms controls Xceed Grid for WinForms cell button Reply To: cell button

User (Old forums)
Member
Post count: 23064

You can set the Visible property to false when setting up the button on the template, then when the TextBox editor gets activated, set it to true, and when the TextBox is deactivated, set it to false again.

If I take the original code posted by Charles, you would add the following in the Form_Load event :

but.Visible = False
AddHandler col1.CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_DeactivatingControl

Then in the CellEditorManager_ActivatingControl event handler :

Dim but As Button = CType(CType(e.Control, WinTextBox).Controls(1), Button)
but.Visible = True

Here is the whole code, with the modifications, and the CellEditorManager_DeactivatingControl event handler :

<code>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim col1 As New Column(“Column1”)
Dim col2 As New Column(“Column2”)
gridControl1.Columns.Add(col1)
gridControl1.Columns.Add(col2)
For i As Integer = 0 To 9

Dim row As Xceed.Grid.DataRow = gridControl1.DataRows.AddNew()
For Each cell As Cell In row.Cells
cell.Value = “Test”
Next
row.EndEdit()
row.Height = row.Height * 2
Next

Dim wtb As New WinTextBox(EnhancedBorderStyle.None)
Dim but As New Button()
but.Text = “My button”
but.BackColor = Color.LightGray
but.Visible = False
wtb.Controls.Add(but)
col1.CellEditorManager = New TextEditor(wtb)
AddHandler col1.CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl
AddHandler col1.CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_DeactivatingControl
col1.CellViewerManager = New TextViewer(wtb)

End Sub

Private Sub CellEditorManager_ActivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)
Dim but As Button = CType(CType(e.Control, WinTextBox).Controls(1), Button)
but.Visible = True
AddHandler but.Click, AddressOf Form1_Click
End Sub

Private Sub CellEditorManager_DeactivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)
Dim but As Button = CType(CType(e.Control, WinTextBox).Controls(1), Button)
but.Visible = False
RemoveHandler but.Click, AddressOf Form1_Click
End Sub

Private Sub Form1_Click(ByVal sender As Object, ByVal e As EventArgs)
System.Diagnostics.Debug.WriteLine(“click”)
End Sub
</code>

Imported from legacy forums. Posted by André (had 563 views)