I am new to WPF, MVVM and EF and I want to develop an application using these technologies.
Simply lets say I have Customer and Orders tables in my DB.
I managed to generate the model using EF. I need a tutorial or example that enables me to learn how to do retrieve Customers and Orders in 2 grids and when selecting a customer it updates the ordergrid to get orders related to that customer.
I'd like to have add/update/delete in both grids.
How to bind a column in a grid to a lookup table?
I believe this is exactly what you are looking for:
http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx#dataset
Under the section "Binding to a Dataset", the project uses a Customer table and an Order table, and shows examples of databinding.
Edit: I don't believe you need to install the WPF toolkit for the datagrid (as the tutorial claims), as it is included in WPF 4.
I am developing a WPF application, The below two being the major modules
The data is obtained from a service and there would be frequent updates after the initial startup.
The grid controls which display the data has to be dynamically created based on a configuration.
Which design pattern would best suit this problem. MVVM pattern does not fit here.
Any suggestions?
Thanks,
using this solution
WPF MvvM DataGrid Dynamic Columns
you can create the columns in your VM and have MVVM bind to both the column definitions and the data for the datagrid.
This is assuming that you need a lot of control over your columns and not just have the datagrid auto generate them from your itemssource binding
Trying to create what i feel should be an easy WPF application. basically what i want it to do is have a autocomplete combobox which is bound to a sql db table. the table has 2 fields(Address and Directions)
once the user selects the record from the address combox the directions textbox below will be filled directions stored in the table.
if there are no records in the address combobox the user can then type in the combobox and add the new entry.
there will be a save button on the form that saves the new entry and will be visible in the list. Im new to WPF applications and have been trying to get this to work for weeks. Any help would be appreciated.
I would start by checking out the following discussion which will point you to several good tutorials on using the MVVM (Model-View-ViewModel) pattern with WPF.
MVVM: Tutorial from start to finish?
Other than that, you haven't really given any indication what you've tried and what isn't working so I can't really offer any other advice. But even the simplest applications in WPF are much cleaner and more easily implemented with MVVM than using code behind and drag and drop data binding.
I'm looking for a WinForms control that would allow me to display data in a table like manner but with some rich content such as different font colors, images. I do not need data-binding etc., just a "table of RichTextBox controls". I suppose it wouldn't be difficult to build such a control myself, but I thought I'd ask first...
Thanks for your answers.
You always have the option of creating your own DataGridView column type. I've done this a few times recently and found that it works quite well. It takes surprisingly little code and knowledge of GDI to put together something very nice.
What information are you trying to display in your grid?
I have seen a lot of discussions going on and people asking about DataGrid for WPF and complaining about Microsoft for not having one with their WPF framework till date. We know that WPF is a great UI technology and have the Concept of ItemsControl,DataTemplate, etc,etc to make great UX. Even WPF has got a more closely matching control- ListView, which can be easily templated to give better UX than a traditional Datagrid like display. And I would say a readymade DataGrid control will kill or hide a lot of creativity and it surely will decrease the innovations in User Experience field.
So what is your opinion about the need of DataGrid in WPF as a Framework component? If you feel it is necessary then is it just because the world is so used to the DatGrid way of data display for many years?
Some other threads having the discussion about DatGrid are here and here
Link to WPF ToolKit - Latest WPF DatGrid
DataGrids are excellent for displaying large amounts of tabular data bound to a backing store.
But what happened in the WinForms world was that people often used them for everything that required a multi-element scrolling list. Souped-up third-party DataGrids soon became available that allowed columns and fields to contain buttons and ComboBoxes and icons, etc.
The DataGrid became a workhorse because there was a need for something it could be coaxed into behaving like. Similar happened to DataTables before generic collections came along--and when you're using lots of DataTables, presenting it in the UI with a DataGrid is the path of least resistance.
I think that when WPF came out, a lot of programmers like me were still thinking in this fashion, and sought out WPF ports of the DataGrid concept.
Can't think of a better control to display tabular data, especially in business apps where you don't want to reinvent the wheel by templating/developing a (Headered)ItemsControl to make it behave like the good old DGV. I'm sure you saw this.
Nobody is disputing that you can make a DataGrid control in WPF yourself. The same can probably be said about WinForms, although it would be more difficult. I've implemented some functionality with ListView - presenting tabular data is easy, you could even say it's well supported. However, the amount of code, manually written code, needed to make an editing ListView is enormous.
The business applications usually require editing of many tables, and you don't want to be creative, you want to be quick. That's why DataGrid is needed in my opinion.
Yes DataGrids will never go away as essential business UI components. People love their spreadsheets and we want to share in that love!
Note that MS are shipping these extra controls - they have created the WPF Toolkit on CodePlex to provide a fast-turnaround, open-source style of deployment.
It already includes a DataGrid and Calendar.
Yes it is!
Among many other controls that ms failed to deliver. (Datepicker, NumericControl)
MS should first give us the tools to get the job done, that is the least i expect from a programming enviroment with the hype of wpf.
It is essential, but you can achieve nearly the same effect with a ListView that is using a GridView, can't you?
After working with WPF for about 2 years now. I would say that a DataGrid is really just a glorified ListBox (since [almost] everything in WPF is styleless).
One could style a ListBox to take an Entity of some sort and show a "record" control for each entry. Depending on how flexible these are made, they could automatically adjust based on the entity passed.