SelectedNode is not working after refresh always showing null










0















Here i am trying to show the last selected node after reload of treeview but the selected node is always null. I am able to find the tree node from the treeview node collection but not able to assign it to tree view. Please suggeest:



 public void LoadTreeViewData()

treeView.Nodes.Clear();// Clear any existing items
treeView.BeginUpdate(); // prevent overhead and flicker
LoadBaseNodes();//Populate all nodes

treeView.EndUpdate();
treeView.Refresh();
treeView.ExpandAll();
if (!string.IsNullOrEmpty(m_oSelectedNode_NAME))

TreeNode treeNodes = treeView.FlattenTree()
.Cast<TreeNode>()
.Where(r => Convert.ToDecimal(r.Tag) == Convert.ToDecimal(m_oSelectedNode_NAME))
.ToArray();

treeView.SelectedNode = treeNodes[0];
treeView.Focus();














share|improve this question
























  • It would be awesome if you could provide a Minimal, Complete, and Verifiable example.

    – mjwills
    Nov 14 '18 at 20:32











  • WinForms? ASP? I can figure out what FlattenTree is doing, but it's not a standard function in the WinForm's TreeView control. Wouldn't it just be treeView.SelectedNode = tns[0]; Not sure why you are doing all that other stuff.

    – LarsTech
    Nov 14 '18 at 20:34











  • Here flatten tree is nothing but returning IEnumerable<TreeNode> collection to find me last save node.Its a winform control.

    – Delta
    Nov 14 '18 at 21:03











  • Here problem is although i found the tree node but when i assign to selectedNode . SelectedNode stays null.

    – Delta
    Nov 14 '18 at 21:07











  • Yes . It is decimal and its returning me the tree node but while assigning the selected node is null.

    – Delta
    Nov 14 '18 at 21:11
















0















Here i am trying to show the last selected node after reload of treeview but the selected node is always null. I am able to find the tree node from the treeview node collection but not able to assign it to tree view. Please suggeest:



 public void LoadTreeViewData()

treeView.Nodes.Clear();// Clear any existing items
treeView.BeginUpdate(); // prevent overhead and flicker
LoadBaseNodes();//Populate all nodes

treeView.EndUpdate();
treeView.Refresh();
treeView.ExpandAll();
if (!string.IsNullOrEmpty(m_oSelectedNode_NAME))

TreeNode treeNodes = treeView.FlattenTree()
.Cast<TreeNode>()
.Where(r => Convert.ToDecimal(r.Tag) == Convert.ToDecimal(m_oSelectedNode_NAME))
.ToArray();

treeView.SelectedNode = treeNodes[0];
treeView.Focus();














share|improve this question
























  • It would be awesome if you could provide a Minimal, Complete, and Verifiable example.

    – mjwills
    Nov 14 '18 at 20:32











  • WinForms? ASP? I can figure out what FlattenTree is doing, but it's not a standard function in the WinForm's TreeView control. Wouldn't it just be treeView.SelectedNode = tns[0]; Not sure why you are doing all that other stuff.

    – LarsTech
    Nov 14 '18 at 20:34











  • Here flatten tree is nothing but returning IEnumerable<TreeNode> collection to find me last save node.Its a winform control.

    – Delta
    Nov 14 '18 at 21:03











  • Here problem is although i found the tree node but when i assign to selectedNode . SelectedNode stays null.

    – Delta
    Nov 14 '18 at 21:07











  • Yes . It is decimal and its returning me the tree node but while assigning the selected node is null.

    – Delta
    Nov 14 '18 at 21:11














0












0








0








Here i am trying to show the last selected node after reload of treeview but the selected node is always null. I am able to find the tree node from the treeview node collection but not able to assign it to tree view. Please suggeest:



 public void LoadTreeViewData()

treeView.Nodes.Clear();// Clear any existing items
treeView.BeginUpdate(); // prevent overhead and flicker
LoadBaseNodes();//Populate all nodes

treeView.EndUpdate();
treeView.Refresh();
treeView.ExpandAll();
if (!string.IsNullOrEmpty(m_oSelectedNode_NAME))

TreeNode treeNodes = treeView.FlattenTree()
.Cast<TreeNode>()
.Where(r => Convert.ToDecimal(r.Tag) == Convert.ToDecimal(m_oSelectedNode_NAME))
.ToArray();

treeView.SelectedNode = treeNodes[0];
treeView.Focus();














share|improve this question
















Here i am trying to show the last selected node after reload of treeview but the selected node is always null. I am able to find the tree node from the treeview node collection but not able to assign it to tree view. Please suggeest:



 public void LoadTreeViewData()

treeView.Nodes.Clear();// Clear any existing items
treeView.BeginUpdate(); // prevent overhead and flicker
LoadBaseNodes();//Populate all nodes

treeView.EndUpdate();
treeView.Refresh();
treeView.ExpandAll();
if (!string.IsNullOrEmpty(m_oSelectedNode_NAME))

TreeNode treeNodes = treeView.FlattenTree()
.Cast<TreeNode>()
.Where(r => Convert.ToDecimal(r.Tag) == Convert.ToDecimal(m_oSelectedNode_NAME))
.ToArray();

treeView.SelectedNode = treeNodes[0];
treeView.Focus();











c# winforms treeview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 21:05







Delta

















asked Nov 14 '18 at 20:17









DeltaDelta

1146




1146












  • It would be awesome if you could provide a Minimal, Complete, and Verifiable example.

    – mjwills
    Nov 14 '18 at 20:32











  • WinForms? ASP? I can figure out what FlattenTree is doing, but it's not a standard function in the WinForm's TreeView control. Wouldn't it just be treeView.SelectedNode = tns[0]; Not sure why you are doing all that other stuff.

    – LarsTech
    Nov 14 '18 at 20:34











  • Here flatten tree is nothing but returning IEnumerable<TreeNode> collection to find me last save node.Its a winform control.

    – Delta
    Nov 14 '18 at 21:03











  • Here problem is although i found the tree node but when i assign to selectedNode . SelectedNode stays null.

    – Delta
    Nov 14 '18 at 21:07











  • Yes . It is decimal and its returning me the tree node but while assigning the selected node is null.

    – Delta
    Nov 14 '18 at 21:11


















  • It would be awesome if you could provide a Minimal, Complete, and Verifiable example.

    – mjwills
    Nov 14 '18 at 20:32











  • WinForms? ASP? I can figure out what FlattenTree is doing, but it's not a standard function in the WinForm's TreeView control. Wouldn't it just be treeView.SelectedNode = tns[0]; Not sure why you are doing all that other stuff.

    – LarsTech
    Nov 14 '18 at 20:34











  • Here flatten tree is nothing but returning IEnumerable<TreeNode> collection to find me last save node.Its a winform control.

    – Delta
    Nov 14 '18 at 21:03











  • Here problem is although i found the tree node but when i assign to selectedNode . SelectedNode stays null.

    – Delta
    Nov 14 '18 at 21:07











  • Yes . It is decimal and its returning me the tree node but while assigning the selected node is null.

    – Delta
    Nov 14 '18 at 21:11

















It would be awesome if you could provide a Minimal, Complete, and Verifiable example.

– mjwills
Nov 14 '18 at 20:32





It would be awesome if you could provide a Minimal, Complete, and Verifiable example.

– mjwills
Nov 14 '18 at 20:32













WinForms? ASP? I can figure out what FlattenTree is doing, but it's not a standard function in the WinForm's TreeView control. Wouldn't it just be treeView.SelectedNode = tns[0]; Not sure why you are doing all that other stuff.

– LarsTech
Nov 14 '18 at 20:34





WinForms? ASP? I can figure out what FlattenTree is doing, but it's not a standard function in the WinForm's TreeView control. Wouldn't it just be treeView.SelectedNode = tns[0]; Not sure why you are doing all that other stuff.

– LarsTech
Nov 14 '18 at 20:34













Here flatten tree is nothing but returning IEnumerable<TreeNode> collection to find me last save node.Its a winform control.

– Delta
Nov 14 '18 at 21:03





Here flatten tree is nothing but returning IEnumerable<TreeNode> collection to find me last save node.Its a winform control.

– Delta
Nov 14 '18 at 21:03













Here problem is although i found the tree node but when i assign to selectedNode . SelectedNode stays null.

– Delta
Nov 14 '18 at 21:07





Here problem is although i found the tree node but when i assign to selectedNode . SelectedNode stays null.

– Delta
Nov 14 '18 at 21:07













Yes . It is decimal and its returning me the tree node but while assigning the selected node is null.

– Delta
Nov 14 '18 at 21:11






Yes . It is decimal and its returning me the tree node but while assigning the selected node is null.

– Delta
Nov 14 '18 at 21:11













1 Answer
1






active

oldest

votes


















0














This problem is happening because i am trying to Update the selected node inside the Tree view after label edit event. I put a timer inside After label edit to resolve the issue and set the Selected node it works for me.



 var tnm = new Timer() Enabled = true, Interval = 30 ;
tnm.Tick += delegate
SetSelectioNode();
tnm.Dispose();
;





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308119%2fselectednode-is-not-working-after-refresh-always-showing-null%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This problem is happening because i am trying to Update the selected node inside the Tree view after label edit event. I put a timer inside After label edit to resolve the issue and set the Selected node it works for me.



     var tnm = new Timer() Enabled = true, Interval = 30 ;
    tnm.Tick += delegate
    SetSelectioNode();
    tnm.Dispose();
    ;





    share|improve this answer



























      0














      This problem is happening because i am trying to Update the selected node inside the Tree view after label edit event. I put a timer inside After label edit to resolve the issue and set the Selected node it works for me.



       var tnm = new Timer() Enabled = true, Interval = 30 ;
      tnm.Tick += delegate
      SetSelectioNode();
      tnm.Dispose();
      ;





      share|improve this answer

























        0












        0








        0







        This problem is happening because i am trying to Update the selected node inside the Tree view after label edit event. I put a timer inside After label edit to resolve the issue and set the Selected node it works for me.



         var tnm = new Timer() Enabled = true, Interval = 30 ;
        tnm.Tick += delegate
        SetSelectioNode();
        tnm.Dispose();
        ;





        share|improve this answer













        This problem is happening because i am trying to Update the selected node inside the Tree view after label edit event. I put a timer inside After label edit to resolve the issue and set the Selected node it works for me.



         var tnm = new Timer() Enabled = true, Interval = 30 ;
        tnm.Tick += delegate
        SetSelectioNode();
        tnm.Dispose();
        ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 14:41









        DeltaDelta

        1146




        1146





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308119%2fselectednode-is-not-working-after-refresh-always-showing-null%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo