grid layout vs table control? - wpf

I need to display in my program number of similar statistics, like:
Name / Age / Salary / Position
John 30 1000 senior
Kate 18 100 intern
... .. .. ...
Totally I need to display several hundreads lines.
The question is what control should I use?
At least I know two options:
use Table control
use Grid layout (then dinamically add labels etc. to the grid)
I think with Grid I will automatically have "custom rendering" because I can add anything into Grid, not only "Label", but also buttons for example. However I'm not sure if I need such possibility.
But I need ability to sort the table by certain column.
So it seems "Table" better feets my needs, however I noticed that it seems that "Table" is not very popular in WPF (am I correct? why?)
So the question is "Should I use Table or there is someting better?" Is it possible to use databinding with Table?
I'm absolutely novice to WPF so sorry for any stupid questions :)

DataGrid and GridView were built for exactly that. When you bind a source it creates a table like row for each row in the source.

Either use a DataGrid or a ListView (with GridView), do not use a Grid, and what is this Table you speak of? If you mean this class, that can only be used in flow documents, which you do not need.
(See the documentation pages for examples or do some searching)

Related

I want a control for Hotel room booking status to show in wpf

I am planing to show hotel room booking status as a color effect. See the image. At want control I want to use?
Dude, this is WPF... you could use just about any control that you want to do that. Ok so I'm exaggerating a bit, but it really is your choice. You should use whatever you're comfortable with. However, if I had to design a UI that looked like your image, I'd probably either go with a ListBox or a DataGrid with a fairly high level of customisation.
If I were to use a DataGrid, the day names could be the column headers and the room names could be the row headers. You'd also need to use some sort of custom ColorConverter class to colour the cell data in the cells.
Using a ListBox, I'd create a DataTemplate to apply to the ListBox.ItemTemplate property that would contain the whole row including the room name. Of course, this would mean that you'd need to structure your data differently to include the name of each room. With a known number of days/columns, you could just use a Grid in the DataTemplate with the Grid.IsSharedSizeScope property set to True to keep the columns of each item aligned.
Good luck and have fun with that... it seems like an interesting project.

How to properly manage a dynamic table of data for gui

So I need to display a DataGrid in WPF. I'm using RadGridView from Telerik and Caliburn.Micro framework using the MVVM strategy.
In my presentation there are differing number of columns, X+2 to be exact as there is always a Label column and a Total column and then X number of others that hold a decimal number.
I do know the number at runtime before I create the classes I need so that could help.
So I'm currently considering a few methods of doing this but some of them have drawbacks so I would love if someone could point me towards a solution.
Create a ViewModel class for each row and for each Cell. The X number will be a collection and binding to it is problematic. I would need to customize the RadGridView itsefl to actually manage this.
Create a DataTable an the run and bind to it. I haven't managed to make this work and not sure if RadGridView actually supports DataTable. This will also not allow me to keep metadata for each cell, something I need to be easily able to update the cells because column + row aren't the only distinguishing keys I need.
Somehow dynamically create a object with x+2 properties to bind to.
Are there any solutions, guides or something out there to help me here?

Data Entry form layout

I would like to get my data entry form to be dislayed in mentioned below sample format. Thing is i almost have 40 fields to be displayed. So i would prefer this format and scrollbar too. Can anyone tell me the better way for these many fields in this format. Let me know the sample piece of code so that i can have better clarity..
Using grid I get 4 columns and almost 25 rows. So UI code getting big..
Apart from grid row definitions or any other way.
Sample format:
This sounds like a typical Grid: http://msdn.microsoft.com/en-us/library/system.windows.controls.grid%28v=vs.95%29.aspx
You want to create one ColumnDefinition per column (so either 2 or 4 depending on how you place your labels (TextBlocks) vs your TextBoxes, and one RowDefinition per row.
That might be tedious with so many fields to do it, so you might want to generate it, it really depends on how you get your fields, and if the fields will never change.
Another solution is the Toolkit's DataForm, which looks exactly like what you've shown:
http://silverlight.codeplex.com/
You can try the demo to see how it looks.
I've never used it, so I can't vouch for its ease of use or power, etc... But at the time of writing, it's in the 'Preview' quality band (see http://silverlight.codeplex.com/wikipage?title=Quality%20Bands&ANCHOR#Preview for explanation).

Dynamic row and column span in WPF DataGrid

I'm working on a new project where the design calls for dynamic rows and columns displayed in some form of grid. I think I can accomplish this very hackishly using the plain ol' Grid, but it seems like it should be possible using a "real" grid.
In my mockup, I circled the tricky bit in red. Under column 1, I have effectively 2 columns of data. The problem is the fact that my data in column 1 can span multiple rows. And the fact that column one is really two pseudo columns and each one can span a different number of rows independently. Note: the data is fake and inconsequential. I'm open to ideas for a good implementation. I can fall back to the Grid and do this all in code behind, I'm open to purchasing a datagrid that may have more power than the DataGrid and my absolute last resort/preference is to restructure this format to something a little more doable.
Thank you for any ideas you can provide.
Most commercial WPF DataGrid implementations handle hierarchical data like this. For example, Telerik's DataGrid (part of RadControls for WPF) supports hierarchical data in multiple formats.
Typically, the default styling is a bit different than yours above, but can be adapted to that format via styling.

Excel like FILTER feature in Silverlight datagrid?

In Excel, there is this feature for filtering the cells of a column.
How can I implement excel like FILTER feature in Silverlight Datagrid?
Please advice. Thanks
AJ
Good question - this is a good feature, but not one that can be implemented in 5 minutes.
You don't want to be overriding the rendering of the standard datagrid in any way (too much work), so you need to take a slightly different approach. One way to do that is to draw your own 'header' above the top of the grid - just a grid, with a border and a stackpanel will get you started. Then you need to enumerate the visible columns of the grid, and create a dropdown corresponding to each, and add that dropdown to the stackpanel. Using a simple linq statement you can get a list of the distinct values in each column. When the user selects a value from the dropdown you can then filter the grid's datasource using that value in a LINQ statement.
In reality this is probably going to be at least a week's worth of work to do properly. If you take the cost of that development and the cost of the testing, and measure that against the cost of a good component suite where they already have filtering built in (most of the major vendors do), then unless you are working for a very low hourly rate you will find it is cheaper to buy the components - it is probably safer too, as the components will be well tested and realtively bug free.
Edit (some time later): what i should also mention though is that if you only want to do this on a couple of columns then you could consider using a column header template. If you take this approach though you will also have to do things like copy the various mouse related animations or transitions that might be part of the original colunm header, just so you can keep some consistency across the top of the grid. Personally i would just go with option one and give the user the ability to filter on any of the columns.

Resources