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

Error Focus RadTreeView !

9 Answers 206 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
uy_2008
Top achievements
Rank 2
uy_2008 asked on 03 Jul 2008, 10:02 AM
Hi Telerik Team !
I have the follw code :

        protected void radTreeTestCase_NodeExpand(object o, RadTreeNodeEventArgs e)
        {
            // expand node STRQ
            if (e.NodeClicked.Level == 0)
            {
                e.NodeClicked.Nodes.Clear();
                int strqID = Convert.ToInt32(e.NodeClicked.ID);
                ......
                    nodeFEAT.Image = "../Images/Level1.gif";
                    nodeFEAT.ExpandMode = ExpandMode.ServerSide;
                    e.NodeClicked.Nodes.Add(nodeFEAT);                  

                e.NodeClicked.Focus();

                }
            }
.....

And then It occur Error :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 1611:                    e.NodeClicked.Nodes.Add(nodeFEAT);
Line 1612: }
Line 1613: e.NodeClicked.Focus();
Line 1614: }

Source File: e:\Project EPM\EPM_site\EPM Website\EPM\ProjectInfo\pgTestCase.aspx.cs    Line: 1613

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.UI.Control.Focus() +31
EVSOFT.EPM.Web.Project.ProjectInfo_pgTestCase.radTreeTestCase_NodeExpand(Object o, RadTreeNodeEventArgs e) in e:\Project EPM\EPM_site\EPM Website\EPM\ProjectInfo\pgTestCase.aspx.cs:1613
Telerik.WebControls.RadTreeView.OnNodeExpand(RadTreeNodeEventArgs e) +56
Telerik.WebControls.RadTreeView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String s) +786
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +242
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3826


Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433


So I can't user method Focus to focus. So You can explain this error for me and help me  solve with this problem to can focus with Control RadTreeView ?

Thank you verry much !

9 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 Jul 2008, 02:28 PM
Hi uy_2008 ,

You can use the OnClientNodePopulated event as a workaround:

        <script type="Text/javascript">
       
        function onNodePopulated(sender, args)
        {
            args.get_node().select();
        }
       
        </script>

        <telerik:RadTreeView
            ID="RadTreeView1"
            runat="server"
            Height="300px"
            Width="300px"
            OnNodeExpand="RadTreeView1_NodeExpand"
            OnClientNodePopulated="onNodePopulated"
        />

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
uy_2008
Top achievements
Rank 2
answered on 04 Jul 2008, 02:44 AM
Hi Albert !
Thank you about your answer. But your solution it still can't use to solve my problem and can't use method Focus().
So, I have the follow code of .aspx page :

.......
<%@ Register Assembly="RadTreeView.Net2" Namespace="Telerik.WebControls" TagPrefix="radT" %>

.......
 <td valign="top">
                                        <radT:RadTreeView AutoPostBack="True" ID="radTreeTestCase" ShowLineImages="False"
                                            runat="server" DragAndDrop="True" meta:resourcekey="radTRequirementResource1" OnClientNodePopulated="onNodePopulated"
                                            OnNodeClick="radTreeTestCase_NodeClick" MultipleSelect="True" OnNodeDrop="radTreeTestCase_NodeDrop" BeforeClientContextMenu="ShowRadMenu1"
                                            OnNodeContextClick="radTreeTestCase_NodeContextClick" Height="512px" Width="100%">
                                        </radT:RadTreeView>
</td>

...........
And then it can't occur attribute
OnNodeExpand with this control, and my error still occur !!!
So, you can help me with this problem?

Thank you again for your whole-hearted help  !
0
Atanas Korchev
Telerik team
answered on 04 Jul 2008, 05:52 AM
Hi uy_2008 ,

You cannot use the Focus method. Please use the workaround mentioned earlier.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Atanas Korchev
Telerik team
answered on 04 Jul 2008, 06:05 AM
Hi uy_2008 ,

You seem to be using RadTreeView classic which requires a different approach:

<script type="text/javascript">
    var onDemandNode = false;
   
    function beforeToggle(node)
    {
        if (node.ExpandOnServer == 2)
            onDemandNode = true;
       
        return true;
    }
   
    function afterToggle(node)
    {
        if (onDemandNode)
        {
            node.Select();
            onDemandNode = false;
        }
    }
</script>

<rad:RadTreeView                           
    ID="RadTree1"
    Runat="server"                           
    BeforeClientToggle="beforeToggle"
    AfterClientToggle="afterToggle"
/>

Again you don't need to call the Focus method.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
uy_2008
Top achievements
Rank 2
answered on 05 Jul 2008, 02:31 AM
Hi Albert !
Thank you very much about your answer. I have tried with your solution, but it can't solve with my problem!!!
I think you misunderstand for my problem. So my problem was: I want to focus to node when i expand it, because sometime my tree have many node (maybe hundreds of nodes on tree), so when i expand it, it doesn't focus to that node and i must scroll to that node again, so now i want to focus to exact that node to easily find it (don't scroll to that node again!!!!).
That's my problem, how to solve with this problem??? You can help me?

Thank you and expect your reply !


P/S: I can't see menu send files to send my code, i very long and big so you can give to me your email to i send to you my code and maybe you see obvious with my problem !!!!


Thank you for all !

0
Coldapoy
Top achievements
Rank 2
answered on 09 Sep 2008, 07:36 AM
yes hi, i dont want to create another thread instead...

i got the same problem though..

how can we achieve this?

many2x thanks team telerik

just me,
coldapoy
0
Coldapoy
Top achievements
Rank 2
answered on 09 Sep 2008, 09:04 AM
its like maintaining scroll position on postback...
0
Coldapoy
Top achievements
Rank 2
answered on 10 Sep 2008, 09:49 AM
team telerik?
0
Veselin Vasilev
Telerik team
answered on 10 Sep 2008, 09:56 AM
Hello Coldapoy,

You can check this KB article:
(ID#419) Scrolling to the selected node


Best wishes,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
uy_2008
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
uy_2008
Top achievements
Rank 2
Coldapoy
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or