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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
Hi Oleg,
Thank you for your prompt and informative response.
Exactly what I was looking for :)
Kind regards,
Ben