PDA

View Full Version : [CLOSED] Error in select node of treepanel into a dropdown



xeo4.it
Oct 03, 2013, 9:52 AM
Hi,
see my example, when I try to select a node of treepanel into a dropdown, I take an error.
Thak you very much

Jimmy



<%@ Page Language="C#" ValidateRequest="false" %>


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>


<%@ Import Namespace="System.Collections.Generic" %>


<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BuildTree(TreePanel1.Root);


this.TreePanel1.GetSelectionModel().Select("2");
}
}


private Ext.Net.NodeCollection BuildTree(Ext.Net.NodeCollection nodes)
{
if (nodes == null)
{
nodes = new Ext.Net.NodeCollection();
}


Ext.Net.Node root = new Ext.Net.Node();
root.Text = "Root";
nodes.Add(root);


string prefix = DateTime.Now.Second + "_";

for (int i = 0; i < 10; i++)
{
Ext.Net.Node node = new Ext.Net.Node();
node.NodeID = i.ToString();
node.Text = prefix + i;
node.CustomAttributes.Add(new ConfigItem("number", i.ToString(), ParameterMode.Raw));
node.CustomAttributes.Add(new ConfigItem("date", JSON.Serialize(DateTime.Now.AddDays(i), JSON.ScriptConverters), ParameterMode.Raw));
node.Leaf = true;
root.Children.Add(node);
}


return nodes;
}


</script>


<!DOCTYPE html>


<html>
<head id="Head1" runat="server">
<title>Remote mode - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />

<style>
.bold-text{
font-weight:bold;
padding-left: 32px;
margin-bottom:2px;
font-size:110%;
}
</style>

</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:DropDownField
ID="Field3"
runat="server"
Editable="false"
Width="300"
TriggerIcon="SimpleArrowDown">
<Component>


<ext:TreePanel
ID="TreePanel1"
runat="server"
Height="300"
Width="450"
AutoScroll="true"
Animate="true"
Mode="Remote"
RootVisible="false"
ContainerScroll="true">

<Fields>
<ext:ModelField Name="number" Type="Int" />
<ext:ModelField Name="date" Type="Date" />
</Fields>


<ColumnModel>
<Columns>
<ext:TreeColumn ID="TreeColumn1" runat="server" DataIndex="text" Text="Text" Flex="1">
<Editor>
<ext:TextField ID="TextField1" runat="server" />
</Editor>
</ext:TreeColumn>


<ext:Column ID="Column1" runat="server" DataIndex="number" Text="Number">
<Editor>
<ext:NumberField ID="NumberField1" runat="server" />
</Editor>
</ext:Column>


<ext:DateColumn ID="DateColumn1" runat="server" DataIndex="date" Text="Date" Format="dd/MM/yyyy">
<Editor>
<ext:DateField ID="DateField1" runat="server" />
</Editor>
</ext:DateColumn>
</Columns>
</ColumnModel>


<SelectionSubmitConfig Encode="true" />


<SelectionModel>
<ext:TreeSelectionModel ID="trmSelModel" runat="server" Mode="Single">


</ext:TreeSelectionModel>
</SelectionModel>


</ext:TreePanel>
</Component>
<Listeners>
<Expand Handler="this.component.getRootNode().expand(true);" Single="true" Delay="10" />
</Listeners>
</ext:DropDownField>
</form>
</body>
</html>

Daniil
Oct 03, 2013, 1:05 PM
Hi Jimmy,

A DropDownField's Component is not rendered until it expands.

Also the Select method (and many others) should not be used during Page_Load

this.TreePanel1.GetSelectionModel().Select("2");
because a TreePanel is not rendered yet.

This method should be used on already rendered tree. For example, during a DirectEvent/DirectMethod.

For initial selection please use a SelectedRows collection.

<ext:TreeSelectionModel ID="trmSelModel" runat="server" Mode="Single">
<SelectedRows>
<ext:SelectedRow RecordID="2" />
</SelectedRows>
</ext:TreeSelectionModel>