Home Forums WinForms controls Other WinForms controls TreeVeiw intercept/cancel event SelectedItemChanged

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18481 |

    in SmartTreeView is there a way to catch the event SelectedItemChanged  before it fires and cancel it? I want to cancel it so the user stays on the current node based on some conditon from an object on a different form/toolwindow that subscribes to SelectedItemChanged.

     

    Thanks,

    Imported from legacy forums. Posted by t (had 2954 views)

    User (Old forums)
    Member
    Post count: 23064

    It is not possible to cancel it.  However, a possible workaround you can use is to to verify it the condition is met in the event handler , and if so, set the selected item back to what it was before the event was triggered.

    e.g.:

    private Xceed.SmartUI.Controls.TreeView.Node previousNode;

    private void Form1_Load(object sender, EventArgs e)

    {

        previousNode = ( Xceed.SmartUI.Controls.TreeView.Node )smartTreeView1.SelectedItem;

        smartTreeView1.SelectedItemChanged += new EventHandler( smartTreeView1_SelectedItemChanged );

    }

    void smartTreeView1_SelectedItemChanged( object sender, EventArgs e )

    {

        if( someCondition )

        {

            smartTreeView1.SelectedItem = previousNode;

        }

        else

        {

            previousNode = ( Xceed.SmartUI.Controls.TreeView.

    Node )smartTreeView1.SelectedItem;

        }

    }

    If your condition is fast to verify, it should not lag, the user should not see that the item was changed and reverted.

     

    Imported from legacy forums. Posted by André (had 379 views)

    User (Old forums)
    Member
    Post count: 23064

    thanks Andre (don’t know how to make the accent on the e)

    Imported from legacy forums. Posted by t (had 3666 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.