Hi,
I'm trying to use the Treelist for a data source with the following definition
public class MyGridItem
{
public string ID { get; set; }
public string Name { get; set; }
public string ParentID { get; set; }
public bool IsIncluded { get; set; }
public bool IsExcluded { get; set; }
}
In markup I've got
<telerik:RadTreeList ID="RadTreeMarkers" runat="server" ParentDataKeyNames="ParentID" DataKeyNames="ID" AutoGenerateColumns="false"
OnNeedDataSource="RadTreeMarkers_NeedDataSource" AllowMultiItemEdit="true" ExpandCollapseMode="Client" EditMode="InPlace"
AllowPaging="false" AllowSorting="false" OnItemDataBound="RadTreeMarkers_ItemDataBound">
<Columns>
<telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" Visible="false" ForceExtractValue="Always"></telerik:TreeListBoundColumn>
<telerik:TreeListBoundColumn DataField="ParentID" UniqueName="ParentID" Visible="false"></telerik:TreeListBoundColumn>
<telerik:TreeListBoundColumn DataField="Name" UniqueName="Name" HeaderText="Mark" ReadOnly="true"></telerik:TreeListBoundColumn>
<telerik:TreeListCheckBoxColumn DataField="IsIncluded" UniqueName="IsIncluded" HeaderText="Included" ForceExtractValue="Always"></telerik:TreeListCheckBoxColumn>
<telerik:TreeListCheckBoxColumn DataField="IsExcluded" UniqueName="IsExcluded" HeaderText="Excluded" ForceExtractValue="Always"></telerik:TreeListCheckBoxColumn>
</Columns>
</telerik:RadTreeList>
And then in the code behind I've got
protected void RadTreeMarkers_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
{
var treeData = MyFacade.GetTreeData();
var treeDataGridItems = treeData.Select(m => new GridItem
{
ID = m.ID.ToString(),
Name = m.Name,
ParentID = m.ParentID.HasValue ? m.ParentID.Value.ToString() : string.Empty,
IsIncluded = m.IsIncluded.HasValue && m.IsIncluded == true,
IsExcluded = m.IsIncluded.HasValue && m.IsIncluded == false
}
).ToList();
RadTreeMarkers.DataSource = treeDataGridItems;
}
protected void RadTreeMarkers_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
{
if (e.Item is TreeListDataItem item)
{
item.Edit = true;
}
}
The intention is for (only) the two checkboxes to be always editable in the client.
However, when rendered in the client the root items are editable but none of the child items is editable.
What am I doing wrong?
Hi Stephen,
I would assume that you would like to initially load all Items in Edit mode. If so, this can be achieved with an approach similar to the one for doing the same in RadGrid, see Put All Items in Edit Mode.
Here is how this would look like for RadTreeList:
protected void RadTreeList1_PreRender(object sender, EventArgs e) { if (!IsPostBack) { foreach (TreeListDataItem item in RadTreeList1.Items) { item.Edit = true; } RadTreeList1.Rebind(); } }
In case the TreeList should be loaded expanded, you can use the ItemDataBound event to expand the root items programmatically
protected void RadTreeList1_ItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e) { var item = e.Item as TreeListDataItem; if (item != null) { item.Expanded = true; } }
Hi @Doncho,
Thanks for the suggestion. Actually I had tried that already as I'd seen it in other posts, but it's not working.
Hi @Doncho,
The only way I was able to get this to work was to set the ExpandCollapseMode to 'Combined' and also add the ItemDataBound method you suggested.
That doesn't seem quite right though - surely it should be able to do it with ExpandCollapseMode as 'Client'?
Stephen.