0

I'm currently working on a "Settings" screen for a project and want to implement a view similar to that found in Visual Studio, where there is a TreeView with a list of options and clicking on one of these options will load a UserControl in an adjacent panel in the same form. I am using a SplitContainer to group these two controls.

I thought that the Load event for the User Control would be triggered when it was displayed in the panel, but this is not the case. I also tried to trigger the Enter event but it still did not work so I tried to call a function when the form was initialized using the following method.

ViewSecurity newViewSecurity = new ViewSecurity(Globals._connectionString); 
// This creates a new instance of the ViewSecurity form from within the TreeView.

And this is the code in the initializing function for the User Control

    public ViewSecurity(string _cString)
    {
        InitializeComponent();
        connectionString = _cString;
        MessageBox.Show("Test");
        populateData();
    }

This method does not work either - the MessageBox does not show up and the function populateData() isn't called either. Any advice on how I could achieve what I am trying to do?

Thanks in advance!

Nischaal Cooray
  • 210
  • 2
  • 12
  • 1
    You should have an event handler when `TreeView` node selection [is changed](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.selectednodechanged.aspx). There you can either construct and initialize `UserControl` or use one, which is attached to node (attached by either using dictionary or `Tag`) and simply add it to `SplitContainer` panel. – Sinatr Oct 08 '14 at 13:26
  • 1
    Look in the Output window for a "First chance exception" notification. If you see one then [this answer](http://stackoverflow.com/a/4934010/17034) tells you what you need to do about it. – Hans Passant Oct 08 '14 at 13:46
  • @Sinatr the line that creates a new instance of the ViewSecurity form is within the `AfterSelect` event handler for the `TreeView`. @HansPassant I do not get a "First chance exception" notification in the output window. Any other suggestions? – Nischaal Cooray Oct 08 '14 at 14:18
  • 1
    Set breakpoint, is this event ever called? Would be to nice to see `AfterSelected` handler code. – Sinatr Oct 08 '14 at 14:27
  • I fixed it. I just needed to clean and rebuild my solution. Thanks! – Nischaal Cooray Oct 08 '14 at 15:39

0 Answers0