Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15869 |

    Is it possible to add a button to a cell next to the cells value. For example: the cell could have the text “Test” and next to that (in same cell) would be a button which when clicked raises a event?

    vb.net

    thanks in advance

    Imported from legacy forums. Posted by troy@querytool.com (had 4452 views)

    Xceed Support
    Member
    Post count: 5658

    Here is some sample code that should meet your requirement:

    <code>
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    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
    wtb.Controls.Add(but)
    col1.CellEditorManager = New TextEditor(wtb)
    AddHandler col1.CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl
    col1.CellViewerManager = New TextViewer(wtb)
    End Sub

    Private Sub CellEditorManager_ActivatingControl(ByVal sender As Object, ByVal e As CellEditorEventArgs)
    AddHandler DirectCast(DirectCast(e.Control, WinTextBox).Controls(1), Button).Click, AddressOf Form1_Click
    End Sub

    Private Sub Form1_Click(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show(“Hello World”)
    End Sub
    </code>

    Imported from legacy forums. Posted by CharlesB (had 365 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks.
    How can I set the buttons visible property to false if another column is selected?

    Imported from legacy forums. Posted by troy@querytool.com (had 360 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m sure I totally understand what you want to do, or what are your needs. Do you want to show the button only when you enter the edition mode of the cell containing the button?

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

    User (Old forums)
    Member
    Post count: 23064

    Yes, that right. I have it set up so when a user clicks on a cell the button appears next to the cell text.
    Now, when a user clicks on another cell I want to set the previous button to invisible.

    Private Sub xg_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xg.CurrentCellChanged

    If xg.Columns.IndexOf(xg.CurrentColumn) = i Then
    addbutton(xg.CurrentCell)
    End If

    End Sub

    Private Sub addbutton(ByVal cell As Cell)
    Dim wtb As New WinTextBox(EnhancedBorderStyle.None)
    Dim but As New Button()

    but.Visible = True
    but.Text = “…”
    but.Width = 20
    but.BackColor = Color.LightGray

    wtb.Controls.Add(but)

    cell.CellEditorManager = New TextEditor(wtb)
    AddHandler cell.CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl

    cell.CellViewerManager = New TextViewer(wtb)

    End Sub

    Imported from legacy forums. Posted by troy@querytool.com (had 422 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, that did the trick.

    Imported from legacy forums. Posted by troy@querytool.com (had 5606 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.