I am having hard time to code for RadTreeView in a RadComboBox. I am using VB.NET. I cannot see the RadTreeView instance at all
from the code behind. Even if I try the FindControl method! I have to dynamically populate the treenodes with data from SQL Server
ASPX code:
<span><telerik:RadComboBox ID="ddDocType" runat="server" Width="200px" ShowToggleImage="True" Style="vertical-align: middle;" >
<ItemTemplate>
<div id="div1">
<telerik:RadTreeView ID="rtvDocType" runat="server" Width="300px" Height="250px">
<DataBindings>
<telerik:RadTreeNodeBinding Expanded="True" />
</DataBindings>
</telerik:RadTreeView>
</div>
</ItemTemplate>
</telerik:RadComboBox></span>
VB.NET code:
Dim tvDoc As RadTreeView = New RadTreeView()
tvDoc =
CType(FindControl("rtvDocType"), RadTreeView)
tvDoc.Nodes.Clear()
Here tvDoc gives a ERROR 'NullReferenceException'
How can I make it work. Is there any working example where the Nodes are dinamically added from code behind for the RadTreeView
in a RadComboBox?
Thanks,
Sanjay
9 Answers, 1 is accepted

Hello Sanjay
Try to use
Dim tvDoc As RadTreeView = New RadTreeView()
tvDoc = CType(FindControl("rtvDocType"), ddDocType.Items(0))
Denis

I tried: tvDoc = CType(FindControl("rtvDocType"), ddDocType.Items(0))
but gives error:
Error 22 Type 'ddDocType.Items' is not defined.
For the 0 in argument it says:
Error 23 Array bounds cannot appear in type specifiers.
Since I have ItemTemplate in aspx code, I also tried CType(FindControl("rtvDocType"), ddDocType.ItemTemplate(0))
But same errors
Please help. Maybe an example in your library with vb.net code will be helpful!
Thanks,
Sanjay

<Items>
<telerik:RadComboBoxItem Text="" />
</Items>
Denis

Sorry after adding the block:
<Items>
<telerik:RadComboBoxItem Text="" />
</Items>
I get the same error!
My new block below:
<telerik:RadComboBox ID="ddDocType" runat="server" Width="200px" ShowToggleImage="True" Style="vertical-align: middle;" >
<ItemTemplate>
<telerik:RadTreeView ID="rtvDocType" runat="server" Width="300px" Height="250px">
<DataBindings>
<telerik:RadTreeNodeBinding Expanded="True" />
</DataBindings>
</telerik:RadTreeView>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem Text="" />
</Items>
</telerik:RadComboBox>
Please help...
Thanks,
Sanjay
Sanjay

I'm a beginner in telerik and use to program in c#. Here is a working sample :
aspx source :
<script type="text/javascript">
function ApplicationNodeClicking(sender, args)
{
var comboBox = $find("<%= RadComboBoxApplications.ClientID %>");
var node = args.get_node()
comboBox.set_text(node.get_text());
comboBox.trackChanges();
comboBox.get_items().getItem(0).set_value(node.get_text());
comboBox.commitChanges();
comboBox.hideDropDown();
}
function StopPropagation(e)
{
if (!e)
{
e = window.event;
}
e.cancelBubble = true;
}
function OnClientDropDownOpenedHandler(sender, eventArgs)
{
// var tree = sender.get_items().getItem(0).findControl("RadTreeViewApplications");
// var selectedNode = tree.get_selectedNode();
// if (selectedNode)
// {
// selectedNode.scrollIntoView();
// }
}
</script>
<div>
<telerik:RadComboBox ID="RadComboBoxApplications" runat="server" ShowToggleImage="True" Style="vertical-align: middle;" OnClientDropDownOpened="OnClientDropDownOpenedHandler" EmptyMessage="Choose an application" oninit="RadComboBoxApplications_OnInit">
<ItemTemplate>
<div id="div1">
<telerik:RadTreeView ID="RadTreeViewApplications" ShowLineImages="false" runat="server" CheckBoxes="true" OnClientNodeClicking="ApplicationNodeClicking" >
</telerik:RadTreeView>
</div>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem Text="" />
</Items>
</telerik:RadComboBox>
</div>
<script type="text/javascript">
var divitem = document.getElementById("div1");
if(null!=divitem)
divitem.onclick = StopPropagation;
</script>
.cs source:
private void bindApplicationsTree(ref RadTreeView objtree)
{
SqlConnection sqlConnection =new SqlConnection("a connection string");
SqlCommand sqlCommand = new SqlCommand("select applicationid,applicationname from TApplications",sqlConnection);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlConnection.Open();
DataSet dsApplications = new DataSet();
sqlDataAdapter.Fill(dsApplications);
sqlConnection.Close();
sqlDataAdapter.Dispose();
objtree.DataValueField = "ApplicationID";
objtree.DataTextField = "ApplicationName";
objtree.DataSource = dsApplications;
objtree.DataBind();
}
protected void RadComboBoxApplications_OnInit(object sender, EventArgs e)
{
Response.Write("<p>combo init fired</p>");
RadComboBox objCombo = ((RadComboBox) sender);
RadTreeView objTree = (RadTreeView)objCombo.Items[0].FindControl("RadTreeViewApplications");
if(null!=objTree)
bindApplicationsTree(ref objTree);
else
{
Response.Write("<p>Warning: Unable to find the tree</p>");
}
}
I hope this help.
Denis

Any news about your problem ? I would appreciate some feedback.
Denis

I first got converted into VB.NET. That went fine.
FOR SOME REASON oninit="RadComboBoxApplications_OnInit"
will do a postback and the selected treenode (radcombobox text) will be left blank.
Then I removed it and let the javascript in the client side populate the value.
Your last reply helped me more than the first two replies.
Thanks,
Sanjay

