UI Design Query : Many to many relationships for data entry UI - wpf

I am designing a Data Entry UI for a WPF application and have a scenario where I need to enter a many-many relationship.
Object A is Parent object. A has an observable collection of type Object B.
Object B has two text fields and an observable collection of Object C which has four text fields.
I need to create a UI which will allow an efficient addition of B and C.
I have created a Nested Tab Control where the outer tab control has object B and it has an inner tab control which can accommodate many object C in it.
However this UI looks ugly and non intuitive. Any suggestions on what would be a better way?

Using a grid in master-detail(-detail) mode?
Check this or this or this to bring you some ideas. Third party vendors like DevExpress and Telerik provide real good data grids and other user controls. Don't know if standard Microsoft DataGrid provides master-detail functionality. But this should give you some ideas.

Related

Using MVP with Windows.Forms - presenter

I have a question on implementing the MVP pattern in a Windows.Forms application.
I have a user control which is used from 2 different forms.
Basically, where shall the presenter be declared (and shall I have 2 different presenters for each form, not a single one for the user control, it be able to distinguish itself what kind of behaviour to take, depending on the form using it) - in the code behind of the user control or of the form using it ? The behaviour (logic on save and filling the fields of the user control) is quite different.
Thank You!
One presentation can have multiple views. e.g. A list of dirs and files in a treeview or in a listview or anything else.
So One Presenter can satisfy the needs of multiple Views.
A View can have extra logic around how to present(convert to relative UI) the information provided by Presenter.
Each View can privately instantiate Presenter. Also because both the view are different UI representation of same presentation, they can should be extracted into a common interface (IXXXView) which can be than be passed into the Presenter.
imo, Passive Views are very strict about converting the data into primitive datatypes which can than be hooked to UI, using a Supervising View would give greater flexibility.

Best Way of implementation for data synchronization and interaction between multiple user controls?

Scenario:
I have one GUI where i have multiple user controls as:
One UserControl on left side of form that contain data filter and selection feature.
Another User Control on right side display/ Report data on selection from left side user control.
Last on is Menu band that control the view of above two control on some menu selection and the view of these controls change but data remain same with some conditional modifications.
That i have do somewhat. Used a global class that have some event which will be raised to make changes/ modification in these views.
I did somewhat accordingly, but i want to implement it in a maintainable way so that if i need to make some modification in functionality then i need not to change whole system.
Is there any design pattern or Model to implement such functionality where you can maintain such type of functionality in win forms?? if yes then please provide some information with some implementation..
I know this is little subjective question, but if reference links provided then much better.
Thanks in advance.
You want a model object shared between the different parts of your UI that implements the INotifyPropertyChanged interface. Use a BindingSource to link the controls with the model.

How to add columns dynamically to a TreeView

I'm fairly new to WPF and C#. I am developing a Tool, which reads data from a DB and puts it into a TreeView.
My class model looks like this:
class Developer //Contains a name, a list of categories and some additional info
class Category //Contains a name, a list of products and some additional info
class Product //Contains a name and some additional info
For now, the tool displays all the Names in a hierarchical manner. This is done via two HierarchicalDataTemplates and a DataTemplate for the leafs.
My question now is, if anyone has an idea how to add some simple columns to the TreeView which should display some double values. The problem is, that the number of additional info(double values) is set through user input. So, if the user wants to display a range of 3 months, I need the TreeView to add 6 columns. (column count = months * 2)
Or maybe someone knows a wpf custom control which suits my needs and works under vs10 and .NET4.0.
Thanks in Advance
The basic TreeView control doesn't support columns, there are specialized controls for this. Those controls are often called TreeList or TreeListView, as it includes the features of a tree and of a ListView. There are some commercial controls (the Telerik RadTreeListView comes to mind ) and there are some free versions floating around (one is in the Windows SDK itself, another one can be found here).
I've used none of them, so I can't tell which one is best suited for your problems, but I would give the last one a try, as it looks as it would solve them.

VB WPF MVC (Model + View + ?)

I have an old VB6 application. I want to recreate it in VB.Net using WPF. But I am a bit confused about the "Model View Controller"-pattern. I have two books about design patterns (GoF and J.Bishop) afair this pattern is indeed not mentioned inside one of the two books. I have also searched the internet I found some java-examples. But I have still no clue how I should use MVC-Pattern (should I?) in my new WPF-application.
Let's say for example my model (in fact it is more complex) is only a wheel rim (circle) with the properties Manufacturer, Diameter and Depth. The user should be able to modify the properties using textboxes and ComboBoxes.
Could somebody create a small example that explaines the MVC-Pattern with WPF?
Of course I like reusable classes to have a feasible concept throughout the whole application.
thanks in advance
Oops
Here's a "brief" description of what the MVC pattern is and how I would apply it to a WPF application.
(I might have a few details slightly off since I've mainy hacked in Silverlight but the concept is similar enough.)
Basically, the idea is to separate concerns and define interfaces between the different parts of an application, with the goal of keeping the code structured and maintainable.
The Model in your example would be pretty much exactly as you described the wheel rim - a WheelRim class with the various properties defined in suitable data types. I would put the model i an separate assembly to keep it apart from the other code, but you can settle for just keeping the model classes in a "Models" folder. The model would also have a "twin" in a database, the model classes being pretty much one-to-one-mapped to tables.
(You might wanna have a look at Linq2SQL or Entity Framework, if the database is defined you can pretty much get the model for free along with suitable database access code.)
The View would be the actual WPF xaml files - Defining the Grid or Canvas or what have you. On the WheelRimView there would be labels and textboxes for displaying or accessing the different properties, perhaps along with product images and the like. The code behind for the view would have all the relevant event handlers (start, button_click and so on) for getting the data from the fields and passing them to the controllers.
The Controller would be any "handler code" that you would use to manipulate the data. We're talking the basic CRUD operations here, along with validation and the like. Also, the controller layer would be responsible for compiling the data in a format that can go seamlessly into the View. The WheelRimController hence would have methods like "GetWheelRimList", "GetWheelRim", "AddWheelRim", "ModifyWheelRim" and "DeleteWheelRim". The methods take the values as in parameters and manipulate the model objects accordingliy. the
I would recommend keeping the code-behind of the xaml files free from any "controller"-ish code like validation, aggregation and the like - the code behind should basically only take the values from the textboxes, listboxes and such and send them on "as is" to the controller methods for processing. Also, you should keep any data formatting code to a minimum when getting data for presentation (i.e., no filtering or translating in the view).
A typical use case of "User opens a wheel rim and edits the diameter" would play out thus in code:
User clicks "Edit" on a list page. The WheelRimView page loads.
The WheelRimView.Load() method (or corresponding) calls WheelRimController.GetWheelRim(wheelRimId).
WheelRimController.GetWheelRim(wheelRimId) gets the corresonding data from a database table and populates the properties of a WheelRim object, which is returned to the WheelRimView.
The WheelRimView inserts the property values into the labels and textboxes.
The user changes the diameter value and clicks the "Save button.
The WheelRimView.Save() method calls the WheelRimController.ModifyWheelRimDiameter(wheelRimId, diameter) method.
The WheelRimController.ModifyWheelRimDiameter(wheelRimId, diameter) method parses the diameter (if it is a string) and loads the model object. It applies the modified value to the model object and saves it into the database.
The WheelRimController.ModifyWheelRimDiameter(wheelRimId, diameter) returns a status code to the WheelRimView (for instance a predefined numeric stating any validation errors) to report the success of the save.
The WheelRimView displays a result message (hopfully "saved") to the user.
I hope that clears a few bits up.
Bevcause of the rich binding support available, WPF (and Silverlight) are well suited to MVVM (Model-View-ViewModel). MVVM is an extension of MVC that uses a view model to bind the current state of a view, instead of manipulating the view directly.
There are a bunch of MVVM frameworks available, as well as Microsoft's own Prism framework (which is arguably more useful if you have a larger, modular application).
WPF is probably more well suited to MVVM (Model-View-ViewModel). I'd recommend reading this MSDN article on MVVM and, perhaps, following their advice. There's also a nice collection of links I found on the Bryant Likes blog.

WinForms - How do I create a table using a custom control for each row?

I want to create a table representing data I have, but I want each row to have a custom display. I have developed a little custom control that represents a row and has a few items in it (text box, check box, progress bar), however how do I now in the main form create multiple instances of this for the data I have?
e.g. is there a winforms control I can use to do this? or do I have to take a panel or something and programmatically do it?
I do need to somehow take responses back. So if someone clicks on the button in the 4th row say then I'll need to be able to tell which row it was from.
As an aside would then be a way to BIND the above mentioned visualization of my data to the data itself, say housed in an Array?
thanks
I see two options here:
You can use a DataRepeater. This control can be found in the Microsoft Visual Basic Powerpack. It allows you to place controls on a template which gets copied for each item in the databound collection.
You can create a custom control and manually place one instance of it for each item in a collection, re-creating databinding for the controls in it. This requires you to either expose the controls inside publicly or as properties of the user control.
However, above options are mostly useful for non-tabular data. If your layout is strictly tabular (i. e. rectangular cells in a grid) then you can create a custom DataGridViewCell which takes some time to understand but not too much code. Putting a progress bar into such a cell shouldn't prove too difficult.

Resources