Menu

Reload / refresh currently active view

Help
mube.co.uk
2009-03-16
2013-04-26
  • mube.co.uk

    mube.co.uk - 2009-03-16

    Hi,

    Before I begin I would like to say that I am currently employing my first usage of the MVC# framework and have found it a pleasure to work with - thank you for your time and effort :)

    I have created an application based on the "Advanced Customization" example, but have ran into a slight hitch that I would like to query before coding additional methods to be explicitly called by a controller...

    I have created a view to add or update a "Client" (database object persisted using NHibernate) depending on the 'Checked' value of a ToolStripButton located on my main form (i.e. the 'Checked' value is set in the task and then checked by the view via the controller, then the view controls are populated or left blank depending on if adding or updating).

    Everything works correctly, except that if I click to add a new "Client" and then click to update the currently active "Client" (I have used a DataGridView on the main form for maintaining the currently active "Client"), then the view doesn't update as it is the currently active view.

    I was wondering if there is some way to reload / refresh a view or a way to dispose a view and then initialize it again?

    Many kind regards,
    Ben

     
    • OVZH

      OVZH - 2009-03-17

      Hello Ben,

      By default view initialization happens only once - when the view gets activated for the first time. So to reinitialize (i.e. to update in your terms) a view you will need to code some extra logic such as below:

      class ClientController...
      ...
          public void Update()
          {
              (View as IInitializable).Initialize();
              // or somewhat else of your choice
          }

      interface IInitializable
      {
          void Initialize();
      }

      Hope it helps :)

      Regards,
      --
      Oleg Zhukov

       
    • mube.co.uk

      mube.co.uk - 2009-03-18

      Hi Oleg,

      Thank you for your prompt and informative response.

      Exactly what I was looking for :)

      Kind regards,
      Ben

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.