Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
Show editor buttons only when hot tracked or if the cell is in edit mode?
posted

Hi All,
I have multi column wintree, one of the columns in WinTree is having an embeded button.  To achieve this the below code is used,

EditorButtonBase editorButton = new EditorButton("Button");
EditorWithText editorText = new EditorWithText();
editorText.ButtonsRight.Add(editorButton);
nodeColumn.Editor = editorText;

This successfully displays the button in the column, however the button is displayed always and this gives the tree a messy feel (more so if there are 2 or more columns having buttons in them).    I have set ShowEditorButtons to ActiveAndHotTracked, but this dosent solve the problem. 
Please suggest how to display the button only when HotTracked or if a cell is active, any help on this will be greatly appreciated.

/spm

Parents
  • 119
    posted

    SPM,

     I was able to solve this problem by setting the editor button as not visible until after the cell was put into edit mode.  It took a combination of settings to get this to work.  First, I set cells to allow full edit but set the Cellclickaction to only select the node.  Then, I used the Tree_MouseDown event to force entry into edit mode.(or to cancel edit if right mouse used to select context menu).  After that, it was a matter of setting value of editor control(PlacesTreeDD), and hiding control on close up.

    Here's some code:

    Private Sub SetTreeProperties()
         ' Make cells fully editable by default, but set cell click action to "SelectNodeOnly"
         Me.MyTree.ColumnSettings.AllowCellEdit = AllowCellEdit.Full
        
    Me.MyTree.Override.CellClickAction = CellClickAction.SelectNodeOnly

         (set other properties)

    End Sub

    Private Sub InitializePlaceColumn()

    ' Set form level reference to column
    colPlace = MyTree.ColumnSettings.RootColumnSet.Columns("Place")

    ' Wire up embedded text editor for place column and embedded dropdown button
    Dim utePlace As New UltraTextEditor
    Dim ddPlace As New DropDownEditorButton

    ' Approach: Using two different click objects in place column. First, there is a swatch
    ' image as "Left Image"(see SetCellVal, cellappearance.image = colorswatch). Second, there's
    ' a dropdown button which is not visible until after user clicks swatch image, which puts
    ' cell into edit mode. Event handler for clicking on swatch "In PlaceColumn_AfterEditMode"
    ' makes dropdown button visible, but cell size is too small, only swatch shows.

    ' Addhandler to respond to click of swatch in left image when cell not in edit mode
    AddHandler utePlace.BeforeEditorButtonDropDown, AddressOf PlaceColumn_DropDown

    ' Create ultratexteditor & dropdown button, add ddbutton to ute right buttons col, ute to column
    With ddPlace
       .ButtonStyle = UIElementButtonStyle.Flat
       .RightAlignDropDown = DefaultableBoolean.True
       .Control = PlacesColumnDD
       .Visible =
    False
    End With

    utePlace.ButtonsRight.Add(ddPlace)
    colPlace.EditorControl = utePlace

    ' In edit mode, clicks on place swatch processed by embedded editorwith text
    Dim editorprovider As IProvidesEmbeddableEditor = DirectCast(utePlace, IProvidesEmbeddableEditor)
    Dim editor As EditorWithText = DirectCast(editorprovider.Editor, EditorWithText)
    AddHandler editor.BeforeEnterEditMode, AddressOf PlaceColumn_BeforeEnterEditMode
    AddHandler editor.AfterEnterEditMode, AddressOf PlaceColumn_AfterEnterEditMode
    AddHandler editor.AfterEditorButtonCloseUp, AddressOf PlaceColumn_AfterEditorButtonCloseUp

    End Sub

    Private Sub MyTree_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyTree.MouseDown

         Dim hittestnode As UltraTreeNode = Me.MyTree.GetNodeFromPoint(Me.MyTree.PointToClient(Me.MousePosition))
         If hittestnode Is Nothing Then Exit Sub

         ' Check for right click to get contextmenu
         If e.Button = MouseButtons.Right Then Exit Sub

         ' Get reference to cell under mouse position
        
    Dim cell As UltraTreeNodeCell = CellFromPoint(Me.MyTree, Me.MousePosition)
        
    If cell Is Nothing Then Exit Sub

         ' If over Place column, then begin edit of place column
        
    If cell.Key = "Place" Then cell.BeginEdit() : Exit Sub

         (other code for other columns)

    End Sub

    Private Sub PlaceColumn_BeforeEnterEditMode(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
        
    ' This allows use of context menu when in edit mode.  This or Tree_Mousedown may be redundant?
         Dim ewc As EditorWithText = DirectCast(sender, EditorWithText)
         If ewc.TextBox.MouseButtons = MouseButtons.Right Then ewc.ExitEditMode(True, False)
    End Sub

    Private Sub PlaceColumn_AfterEnterEditMode(ByVal sender As Object, ByVal e As EventArgs)
         Dim ewc As EditorWithText = DirectCast(sender, EditorWithText)
         Dim ddeb As DropDownEditorButton = DirectCast(ewc.ButtonsRight(0), DropDownEditorButton)

         ddeb.Visible = True

         ddeb.DropDown()

    End Sub

    Private Sub PlaceColumn_DropDown(ByVal sender As Object, ByVal e As BeforeEditorButtonDropDownEventArgs)
         Dim cell As UltraTreeNodeCell = MyTree.ActiveCell

         If Not cell Is Nothing AndAlso Not cell.Value Is Nothing Then
             Pl
    acesColumnDD.CurrentPlaceID = cell.Value.ToString
         End
    If
    End Sub

    Private Sub PlaceColumn_AfterEditorButtonCloseUp(ByVal sender As Object, ByVal e As EditorButtonEventArgs)
         Dim ewc As EditorWithText = DirectCast(sender, EditorWithText)
         Dim ddeb As DropDownEditorButton = DirectCast(ewc.ButtonsRight(0), DropDownEditorButton)

         ' Hide dropdown button
        
    ddeb.Visible = False

         ' Exit editmode for the editor
        
    ewc.ExitEditMode(True, True)

         ' Set active cell to nothing so back to selecting entire node
        
    Me.MyTree.ActiveCell =
    Nothing
    End Sub

    JC

Reply Children