This is a migrated thread and some comments may be shown as answers.

two-way binding on custom column

1 Answer 64 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Stig
Top achievements
Rank 1
Stig asked on 07 Dec 2015, 11:13 AM

Hi

I have a little issue with a custom column i have created for the treelist.

The column is almost working as expected - it can get the value from the datasource, however when the value should be updated back to the database it dosnt happen, althou the ExtraceValues() is called and is returning the new value - i think i might be missing something simple - how you are able to help, thanks.

 

here is the asp markup for the column:

 

<%@ Register TagPrefix="CustomColumns" Namespace="CustomColumns" %>

        <telerik:RadTreeList runat="server" ID="MenuTree" DataSourceID="IPPlanV4Menu" DataKeyNames="MenuID" ParentDataKeyNames="ParentMenuID" AutoGenerateColumns="False" EditMode="InPlace" >
            <Columns>
.....
                <CustomColumns:ValueSetColumn ValueSet="No=0,Yes=1" UniqueName="ForceVisible" HeaderText="Force Visible" DefaultInsertValue="0" DataField="ForceVisible">
                    <HeaderStyle Width="70px" />
                    <ItemStyle Width="60px" />
                </CustomColumns:ValueSetColumn>
                <telerik:TreeListEditCommandColumn AddRecordText="Add" CancelText="Cancel" EditText="Edit" InsertText="Insert" ShowAddButton="true" ShowEditButton="true" HeaderText="">
                    <HeaderStyle Width="70px" />
                </telerik:TreeListEditCommandColumn>
                <telerik:TreeListButtonColumn UniqueName="DeleteCommandColumn" Text="Delete" CommandName="Delete" HeaderText="">
                    <HeaderStyle Width="40px" />
                </telerik:TreeListButtonColumn>
            </Columns>
        </telerik:RadTreeList>

 

and the code for the column with the two item templates

Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Web.UI.WebControls
Imports Telerik.Web.UI

Namespace CustomColumns

    Public Class ValueSetColumn
        Inherits TreeListTemplateColumn
        Private _valueSet As String
        Private ListItems As OrderedDictionary

        Public Property ValueSet As String
            Get
                Return _valueSet
            End Get
            Set(value As String)
                Dim strs As String()
                _valueSet = value
                For Each Str As String In value.Split(",")
                    strs = Str.Split("=")
                    ListItems.Add(strs(0), strs(1))
                Next
            End Set
        End Property

        Public Sub New()
            Me.ListItems = New OrderedDictionary()
            Me.ItemTemplate = New ItemValueSetTemplate(Me)
            Me.EditItemTemplate = New EditValueSetTemplate(Me)
        End Sub

#Region "EditValueSetTemplate"
        Private Class EditValueSetTemplate
            Implements IBindableTemplate
            Private owner As ValueSetColumn = Nothing
            Private ddl As RadDropDownList = Nothing

            Public Sub New(owner As ValueSetColumn)
                Me.owner = owner
            End Sub

            Public Function ExtractValues(container As Control) As IOrderedDictionary Implements IBindableTemplate.ExtractValues
                Dim values As New OrderedDictionary()
                values(owner.DataField) = ddl.SelectedItem.Value
                Return values
            End Function

            Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
                ddl = New RadDropDownList()
                ddl.Enabled = True
                ddl.MergeStyle(owner.ItemStyle)
                AddHandler ddl.DataBinding, AddressOf DataBinding
                container.Controls.Add(ddl)
            End Sub

            Private Sub DataBinding(ByVal sender As Object, ByVal e As EventArgs)
                Dim item As DropDownListItem
                Dim DDL As RadDropDownList = DirectCast(sender, RadDropDownList)
                Dim container As TreeListEditableItem = DirectCast(DDL.NamingContainer, TreeListEditableItem)
                Dim selectedvalue As String = DirectCast(container.DataItem, DataRowView)(owner.DataField).ToString()
                DDL.Items.Clear()
                For Each ditem In owner.ListItems
                    item = New DropDownListItem(ditem.Key, ditem.Value)
                    item.Selected = (item.Value = selectedvalue)
                    DDL.Items.Add(item)
                Next
            End Sub
        End Class
#End Region

#Region "ItemValueSetTemplate"
        Private Class ItemValueSetTemplate
            Implements IBindableTemplate
            Private owner As ValueSetColumn = Nothing
            Private ddl As RadDropDownList = Nothing

            Public Sub New(owner As ValueSetColumn)
                Me.owner = owner
            End Sub

            Public Function ExtractValues(container As Control) As IOrderedDictionary Implements IBindableTemplate.ExtractValues
                Dim values As New OrderedDictionary()
                values(owner.DataField) = ddl.SelectedItem.Value
                Return Values
            End Function

            Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
                ddl = New RadDropDownList()
                AddHandler ddl.DataBinding, AddressOf DataBinding
                ddl.MergeStyle(owner.ItemStyle)
                ddl.Enabled = False
                container.Controls.Add(ddl)
            End Sub

            Private Sub DataBinding(ByVal sender As Object, ByVal e As EventArgs)
                Dim item As DropDownListItem
                Dim DDL As RadDropDownList = DirectCast(sender, RadDropDownList)
                Dim container As TreeListEditableItem = DirectCast(DDL.NamingContainer, TreeListEditableItem)
                Dim selectedvalue As String = DirectCast(container.DataItem, DataRowView)(owner.DataField).ToString()
                DDL.Items.Clear()
                For Each ditem In owner.ListItems
                    item = New DropDownListItem(ditem.Key, ditem.Value)
                    item.Selected = (item.Value = selectedvalue)
                    DDL.Items.Add(item)
                Next
            End Sub
        End Class
#End Region

    End Class

End Namespace

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Dec 2015, 08:33 AM
Hello Stig,

I believe you managed to find a solution for your case as described in our other conversations. I will check the sample provided in your formal support ticket and let you know if I notice something of importance.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeList
Asked by
Stig
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or