开发者

Is my approach to Winforms coding old-school

开发者 https://www.devze.com 2023-02-13 14:34 出处:网络
The project I\'m working on is quite large and we have a framework we developed for building simple UI screens easily.The two fundamental types we have are Search (search parameters + grid of results)

The project I'm working on is quite large and we have a framework we developed for building simple UI screens easily. The two fundamental types we have are Search (search parameters + grid of results) and Detail (a set of editors that are usually populated from some model object).

The application is all C# .NET Winforms.

In the Detail we have the following process.

  • Load - Populate the edit controls based on the appropriate model object. Invoked just prior to the Detail being shown

User clicks ok

  • Validate - V开发者_JAVA百科alidates the detail to ensure everything is consistent
  • Accept - Copy the updated control values back into the model

This all works nicely for simple stuff but in more complex cases I've noticed perhaps the above approach is not the smoothest.

The more complex cases mentioned above are when a Detail represents a model object and there is a grid embedded in the Detail which holds 'child' objects which can be added and removed. Typically you want to launch the child Detail and pass in the parent model object, however it is not fully populated/up to date at this point because that only happens when OK is clicked. I find myself working round this in an annoying fashion sometimes which leads me to the following question.

At a high-level, is the accepted/best practice approach for Detail screens like I describe to copy values to the model object when the control is changed, rather than waiting until OK is clicked?

If so, in a Winforms app, what is the best way to achieve this? I found some articles mentioning Control.DataBindings but it's not ideal because of the lack of compile-time safety on the binding. I've read WPF has good binding support, but unfortunately, I'm not using WPF.


For Winforms I would suggest that you look into the Model-View-Presenter pattern. http://msdn.microsoft.com/en-us/magazine/cc188690.aspx


This might help:

Walkthrough: Creating a Master/Detail Form Using Two Windows Forms DataGridView Controls

http://msdn.microsoft.com/en-us/library/y8c0cxey.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号