CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Location
    India
    Posts
    30

    Thumbs up Getting Focus on the main window from Popup window

    I'm working in a windows project(WPF). the situation is, i'm saving a few datas into a database from a popup window. after saving I want those values to be reflected in the main window.

    How do I achieve it?
    I would like to know, as to where the focus goes after the popup window is closed.
    is there any way to track the focus ?

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Getting Focus on the main window from Popup window

    Open the form as a modal dialog, and the focus will return to the main form when the pop-up is closed:
    Code:
    Form2 f2 = new Form2();
    f2.ShowDialog(this);
    As for the data being reflected on the main form, use delegates.
    It's not a bug, it's a feature!

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Getting Focus on the main window from Popup window

    If you use data binding, then you don't really need to do anything - it will get updated automatically.

    If the main form contains a list (and the 2nd form) adds items to the list, all you need to do is create an observable collection containing items derived from INotifyPropertyChanged.

    Next you'll bind the list view (or whatever control it is) to the ObservableCollection derived class. When you insert into the database, insert the item into the collection.

    The new item will automatically appear in the main form.

    The plumbing inside of WPF greatly reduces the messing around that you had to do previously with regard to updating different data in different controls.

    Now, you can have multiple controls bound to the same data, and if the underlying data changes, the changes will be reflected across all controls.

    If you need a sample, let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured