Current filter:
                                You should refresh the page.
                                  • Hello,

                                    I've reviewed some of the tickets concerning adding a button to a treelist column, but I cannot seem to get mine to show.  I see the column to the left of the column with the data.  Attached is the image and below is the code for setting up my treelist.  It is being populated from a datatable.

                                    Imports DevExpress.XtraEditors.Repository
                                    Imports DevExpress.XtraTreeList
                                    Imports DevExpress.XtraTreeList.Columns
                                    Imports DevExpress.XtraTreeList.Nodes

                                    Public Class Form2

                                        Dim bTreeCreated As Boolean = False
                                        Dim strCurrentError As String = ""

                                        Dim buttonEdit As RepositoryItemButtonEdit
                                        Dim CurrentTotalValue As Integer = 0

                                        Dim dtSOLines As New DataTable

                                        Private Sub MakeTree(Optional ByVal bDataRefresh As Boolean = True)

                                            If bDataRefresh Then
                                                tvSOLine.DataSource = Nothing
                                                tvSOLine.Refresh()
                                            End If
                                            tvSOLine.Nodes.Clear()
                                            bTreeCreated = False

                                            strCurrentError = "Add column to treelist to house all nodes"
                                            If tvSOLine.Columns.Count = 0 Then
                                                tvSOLine.BeginUpdate()
                                                Dim col1 As New TreeListColumn
                                                Dim col2 As New TreeListColumn
                                                col2.Name = "Button"
                                                col2.FieldName = "button"
                                                col2.VisibleIndex = 2
                                                col2.OptionsColumn.AllowEdit = True
                                                buttonEdit = New RepositoryItemButtonEdit
                                                tvSOLine.RepositoryItems.Add(buttonEdit)
                                                tvSOLine.ShowButtonMode = ShowButtonModeEnum.ShowAlways
                                                col2.ColumnEdit = buttonEdit
                                                col1.Name = "Item"
                                                col1.FieldName = "ItemCode"
                                                col1.VisibleIndex = 1
                                                tvSOLine.Columns.Add(col1)
                                                tvSOLine.Columns.Add(col2)
                                            End If

                                            tvSOLine.Columns(0).Width = 60
                                            tvSOLine.Columns(1).Width = PanelControl1.Width - 60

                                            tvSOLine.OptionsView.AutoWidth = False
                                            tvSOLine.OptionsView.ShowIndicator = False
                                            tvSOLine.OptionsView.ShowHorzLines = False
                                            tvSOLine.OptionsView.ShowVertLines = False
                                            tvSOLine.OptionsSelection.EnableAppearanceFocusedCell = True

                                            If bDataRefresh = True Or dtSOLines.Rows.Count = 0 Then
                                                dtSOLines = New DataTable
                                                'dtSOLines = GetSalesOrderLines()
                                                If dtSOLines.Rows.Count = 0 Then
                                                    MsgBox("No data returned.", MsgBoxStyle.Information, "No Data")
                                                    Exit Sub
                                                End If
                                            End If

                                            strCurrentError = "Populate top nodes"

                                            Dim pn As TreeListNode
                                            Dim CurrentLine As String = ""
                                            Dim CurrentItem As String = ""
                                            Dim BeginRows As Boolean = True

                                            Dim dv As New DataView(dtSOLines)
                                            Dim dtLine As DataTable = dv.ToTable

                                            For Each row As DataRow In dtLine.Rows
                                                If BeginRows Then
                                                    CurrentItem = row.Item("ItemCode")
                                                    pn = tvSOLine.AppendNode(New Object() {buttonEdit, ItemHeaderNode(row)}, -1)
                                                    pn.Tag = "ItemCode |" & row.Item("ItemCode") & "| LineNum |" & row.Item("LineNum")
                                                    CurrentTotalValue = CurrentTotalValue + row.Item("OrderedValue")
                                                    BeginRows = False
                                                Else
                                                    If row.Item("ItemCode") <> CurrentItem Then
                                                        CurrentItem = row.Item("ItemCode")
                                                        pn = tvSOLine.AppendNode(New Object() {buttonEdit, ItemHeaderNode(row)}, -1)
                                                        pn.Tag = "ItemCode |" & row.Item("ItemCode") & "| LineNum |" & row.Item("LineNum")
                                                        CurrentTotalValue = CurrentTotalValue + row.Item("OrderedValue")
                                                    End If
                                                End If
                                            Next

                                        End Sub

                                        Private Function ItemHeaderNode(ByVal drLine As DataRow) As String

                                            strCurrentError = "Setting top sales order line nodes"

                                            Try

                                                Dim n As String = ""

                                                n = n & PadLeft(drLine("ItemCode"), 15)
                                                n = n & PadLeft(drLine("CustItemRef"), 20)
                                                n = n + Space(2)
                                                n = n & PadRight(drLine("Description"), 60)

                                                Return n

                                            Catch oE As Exception

                                                LogEvent(Me.GetType.Name,
                                                    System.Reflection.MethodBase.GetCurrentMethod.Name,
                                                    "Catch Error.  Last message: " & strCurrentError & vbCrLf & oE.Message,
                                                    "Error: " & strCurrentError,
                                                    oE)

                                            End Try

                                        End Function

                                        Public Function PadLeft(ByVal strString As String, intLengthDesired As Integer) As String
                                            Dim ReturnString As String = String.Empty

                                            If String.IsNullOrEmpty(strString) Then

                                                REM ***  Just return spaces if the original string is null
                                                REM ***
                                                ReturnString = Strings.Space(intLengthDesired)

                                            ElseIf (Len(strString) >= intLengthDesired) Then

                                                REM ***  Cut the string off it is longer than desired
                                                REM ***
                                                ReturnString = Strings.Left(strString, intLengthDesired)

                                            Else

                                                REM ***  Pad spaces to desired length
                                                REM ***
                                                ReturnString = Strings.Space(intLengthDesired - Len(strString)) & strString

                                            End If

                                            Return ReturnString

                                        End Function

                                        Public Function PadRight(ByVal strString As String, intLengthDesired As Integer) As String
                                            Dim ReturnString As String = String.Empty

                                            If String.IsNullOrEmpty(strString) Then

                                                REM ***  Just return spaces if the original string is null
                                                REM ***
                                                ReturnString = Strings.Space(intLengthDesired)

                                            ElseIf (Len(strString) >= intLengthDesired) Then

                                                REM ***  Cut the string off it is longer than desired
                                                REM ***
                                                ReturnString = Strings.Left(strString, intLengthDesired)

                                            Else

                                                REM ***  Pad spaces to desired length
                                                REM ***
                                                ReturnString = strString & Strings.Space(intLengthDesired - Len(strString))

                                            End If

                                            Return ReturnString

                                        End Function

                                        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                                            MakeTree()
                                        End Sub

                                    End Class

                                Show all comments
                                • Maxim L (DevExpress Support) 10.18.2019

                                  Hi,
                                  As I see, you don't call the EndUpdate method after the BeginUpdate(). It can be the cause of the issue. Please check it. Also, I see that you try to add the buttonEdit object in the AppendNode method, you don't need to do this. It is enough to set the column's ColumnEdit property to the required item.
                                  I suggest you take a look at the Assigning Editors to Columns article it describes on how you can assign editors to columns.

                                • Barb Harris 10.18.2019

                                  I added the EndUpdate and changed the append node to tvSOLine.AppendNode(New Object() {"", ItemHeaderNode(row)}, -1), changing the first column to an empty space since you suggest I do not need to add the buttonedit to the node through ApppendNode, but I still see just an empty column and not a button.  I looked at your suggested article and my code appears to look the same - I add the repositoryitembuttonedit to the treelist via tvSOLine.Repositopryitems.add() and add the buttonEdit to the col2.ColumnEdit before adding the columns to the treelist.  And I can type text into the column that is supposed to have the button.

                                • Maxim L (DevExpress Support) 10.21.2019

                                  Hi,
                                  I've created a small sample project based on your code, and it operates correctly.
                                  As for your original project, to narrow down the issue, I suggest you add columns and the ButtonEdit editor as I did in my sample. If TreeList displays the editor correctly, try to look for the issue in your code. Follow steps from the Case 3 section of the How to investigate the issue and determine why it occurs in your project KB article. Make sure that all rows where you add columns/editors are reachable and comment out all excessive code. Please try this and let me know your results.

                                • Barb Harris 10.21.2019

                                  Ok, comparing to your sample, I guess I am seeing the button edit column and I can put text in it, but I guess I was expecting to see an actual button. Is there a way to make it look like a simple button instead of just text in a column?

                                • Maxim L (DevExpress Support) 10.21.2019

                                  Hi,
                                  You can use the approach from the How to show a button which occupies a whole grid cell KB article. Set the TextEditStyle property to HideTextEditor.

                                • Barb Harris 10.21.2019

                                  Ok, thank you for that. I now see the button and it looks good.  Is there a way to only show the button on the top level nodes?   I have attached your project with a few updates trying to achieve that goal.  Even if I can just hide the text that would work. Or is there a better way to achieve a button to the left of only the top nodes of a treelist that does not include a column of its own?

                                • Maxim L (DevExpress Support) 10.22.2019

                                  Hi,
                                  As far as I understand, you want to add the ButtonEdit editor only to the root node cells of the first column. All child node cells should have a usual TextEdit editor, am I right?

                                • Barb Harris 10.22.2019

                                  Correct, although I do not need any kind of editor in the child nodes, only the Button Edit on the top node, but I know columns apply to all nodes, so I was hoping to shrink up the leading column cell on the child nodes, but did not know if this was possilbe.

                                  My ultimate goal is to have an Add button to the left of the top nodes that will fire an event when clicked. The child nodes do not need to have anything.

                                1 Solution

                                Creation Date Importance Sort by

                                Hi,
                                In this case, you can use a different approach.
                                Instead of assigning ButtonEdit for the whole column, you can assign it for individual cells. For this, you can handle the CustomNodeCellEdit event and assign the editor for the required node cells. Please note that editors used in this event handler should be completely initialized and adjusted beforehand. This event is intended to only assign a ready-to-use editor to a cell.

                                • Barb Harris 11.12.2019

                                  Thank you.  That is what I needed.