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
Here's the function I used for CellFromPoint. It simply uses a While Loop to walk up chain of parent UIElements until it finds a parent UltraTreeNodeCellUIElement which is used to get the cell reference. Failing that, it returns a null object (VB: Nothing.).
Private Function CellFromPoint(ByVal tree As UltraTree, _ ByVal location As Point) As UltraTreeNodeCell
Dim controlElement As UIElement = tree.UIElement
If controlElement Is Nothing Then Return Nothing
Dim elementAtPoint As UIElement = controlElement.ElementFromPoint(_ tree.PointToClient(location)) Dim cellAtPoint As UltraTreeNodeCellUIElement
While Not (elementAtPoint Is Nothing) If TypeOf (elementAtPoint) Is UltraTreeNodeCellUIElement Then cellAtPoint = DirectCast(elementAtPoint, UltraTreeNodeCellUIElement) Return cellAtPoint.Cell End If elementAtPoint = elementAtPoint.Parent End While
Return Nothing
End Function
i have a question to your code:
I think that CellFromPoint() is written by yourself?! Can you show the code for that? How do you find out which cell was clicked? Thanks a lot
Hi,
Thanks for the reply. In my implementation the CellClickAction is set to ActivateCell and I will not be able to change this property because of some other implementations based on this property(.. and it is important from client perspective). Also, I assume the above solution would work i.e., the button in a cell gets displayed only when cell is in edit mode, but I also wanted the button to be displayed when the cell is hot tracked. The ShowEditorButton property seems to suggest that WinTree supports this capablity but it dose not work that way - please provide some inputs about this property and what effect does the tree has using one of this properties.
Does Infragistics has some solution for this problme?
Thanks for any help,
spm
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 columncolPlace = MyTree.ColumnSettings.RootColumnSet.Columns("Place") ' Wire up embedded text editor for place column and embedded dropdown buttonDim utePlace As New UltraTextEditorDim 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 modeAddHandler utePlace.BeforeEditorButtonDropDown, AddressOf PlaceColumn_DropDown ' Create ultratexteditor & dropdown button, add ddbutton to ute right buttons col, ute to columnWith ddPlace .ButtonStyle = UIElementButtonStyle.Flat .RightAlignDropDown = DefaultableBoolean.True .Control = PlacesColumnDD .Visible = FalseEnd With utePlace.ButtonsRight.Add(ddPlace)colPlace.EditorControl = utePlace' In edit mode, clicks on place swatch processed by embedded editorwith textDim editorprovider As IProvidesEmbeddableEditor = DirectCast(utePlace, IProvidesEmbeddableEditor)Dim editor As EditorWithText = DirectCast(editorprovider.Editor, EditorWithText)AddHandler editor.BeforeEnterEditMode, AddressOf PlaceColumn_BeforeEnterEditModeAddHandler editor.AfterEnterEditMode, AddressOf PlaceColumn_AfterEnterEditModeAddHandler editor.AfterEditorButtonCloseUp, AddressOf PlaceColumn_AfterEditorButtonCloseUp
' Wire up embedded text editor for place column and embedded dropdown buttonDim utePlace As New UltraTextEditorDim 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.
' Create ultratexteditor & dropdown button, add ddbutton to ute right buttons col, ute to columnWith ddPlace .ButtonStyle = UIElementButtonStyle.Flat .RightAlignDropDown = DefaultableBoolean.True .Control = PlacesColumnDD .Visible = FalseEnd With
utePlace.ButtonsRight.Add(ddPlace)colPlace.EditorControl = utePlace
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)
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()
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 PlacesColumnDD.CurrentPlaceID = cell.Value.ToString End IfEnd 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 = NothingEnd Sub
JC
Please tell us if you solved your issue and how.