Subrows into a row in GridView using WPF & C# - wpf

In my gridview I need to aggregate subrows into each row, something like in p2p emule/amule application where you can do double click to each file you are downloading and then under it you can see the parts of the file from where you are downloading.
Is it possible in WPF?
Thanks.

You could do a few things:
Add some container (ie: another Grid or a StackPanel) to the Grid row. This would let you add multiple objects to the grid row. On your "double click" event, you could change the visibility to show those objects.
Use a TreeView with a HierarchicalDataTemplate, and treat this as hierarchical data. This is most likely the more "correct" approach. The Displaying Hierarchical Data sample on MSDN walks through the process of this.

Related

Fixed Document Tables?

I am looking for a layout control or other means of laying out data in a tabular format on a Fixed Document for reporting. I have used MigraDoc quite extensively in non WPF projects and its table object allows for a granular layout for each piece of data to be displayed in the table. Borders can be turned off on the cell level, columns can be merged/spanned, etc. Are there any controls that offer this kind on control within WPF? I have not seen where the DataGrid or the Grid will do what I need... easily. My data is not bound as I need to have full control over how it is displayed. I am not using a flow document so I cannot use the table object that it offers. Anyone have any suggestions? For now, I have resorted to programmatically creating a Grid and then inserting a Border containing a TextBlock within each cell. There just has to be a cleaner way!
BTW - I am looking to use native WPF controls in this project which is the reason that I am not using MigraDoc.

WPF ListView Grouping - with a twist

I have a treeview right now with a templateselector. Basically each tree node on the root is a "category" of some type of data and each child node under those are displayed in a specific way (via the template selector).
This allows me to show different data in a single control easily just using binding. My problem is that it's not working out so well visually. I would like to have a grid style (ListView.GridView) under each root node.
I was looking at ListView grouping but is it possible to define different columns for each group? Since I doubt that is possible, what are some options? I would like to allow the user to expand and collapse the groups just like a treeview but see a GridView under each node with scroll bars, etc.
I don't think that ListView supports different headers in groups. It's just grouping of rows. Looks like you're going to have to create a new ListView under each tree node. You might try a data grid. In WinForms you can bind to multiple tables and the grid will group by table which can be expanded and collapsed which would in effect show different columns. If you're using MVVM (I assume some collection or hierarchy model) I have no idea how you'd accomplish that with a data grid.
You may achieve what you want relatively simple if you adopt the MVVM architecture.
Each node on the tree is of a certain type (ViewModel). Each data type would be bind to a specific View. Each View can be a ListView with any columns you want.
I recommend you read about MVVM and adopt it in order to achievewhat you need. I found that the adoption of MVVM leads to applications with a much cleaner architecture and code.

Using the DragDropTarget with a traditional Grid

Silverlight 4 now provides controls to handle Drag and Drop actions. All the Target Controls seem to inherit from DragDropTarget Like so
public class MyControlDragDropTarget : DragDropTarget<TItemsControlType,TItemsContainerType>
.
.
.
A number of controls have pre-defined DragDropTargets including the DataGrid, ListBox, Panels
Which is all very well, but I want to drag and drop from a grid not a datagrid, and there is no pre-defined one for a normal grid.
I actually want to drag a given row from the grid, but without a Container Type for a Grid I cannot work out how to define a DragDropTarget control for the grid.
Only way I can think is instead of using a grid - I use a listbox (for which there is a DragDropTarget) and then place a StackPanel or Grid in each row (which has one row of 'n' columns)
Anyone got any ideas
Ta in advance
A "normal grid" is simply another form of panel, there is no need for specialised DragDropTarget for the Grid, the existing PanelDragDropTarget is sufficient for a "normal grid".
Its important grasp that the Grid does not support the concept of "rows containing cells containing UI elements". The rows and columns of a Grid are entirely equal and are defined purely for layout purposes. UIElement children of a Grid are laid out entirely independently of each other, there is no concept of a set of values belonging to either a column or a row that can be moved or operated on as a group (like picking up a row and dragging it).
Sounds like you have already got an answer for yourself, use the ListBox instead.
BTW, DragDropTarget isn't provided by Silverlight 4 but rather the Silverlight Toolkit. This is an important distinction because the current quality band assigned to DragDropTarget is "Experimental". You need to think carefully about this if you want to use such code in some production release of your own.

WPF DataGrid - Setting RowDetails programmatically

I'm using the WPF DataGrid, and I'd like to know if there is any way I can access the DataGridRow's RowDetails programatically.
For example, when the user selects the row, I'd to grab some data from somewhere (say, a database), and display it in the RowDetails.
All of the examples I've seen tend to just display some extra bound data that isn't included in the columns for the row.
You could display some extra data but lazy-load it on SelectionChanged.
It usually is not easy to work directly with the WPF controls, they are not really meant to be used without a backing databound model.
If you have all the data in list of objects (or something similar) then you can do all sorts of fun things. I'm using a WPF Datagrid in this manner, and when a user selects a row, I think populate an editor control above the grid with the row item plus additional details.
That said, there's nothing stopping you from adding in additional information in the grid that's normally hidden and a trigger on row selection to show the additional data
you can use the following code
DataRowView row = (DataRowView)MyDataGrid.SelectedItem;
string strName = row.Row["Name"].ToString(); //where "Name" is the column name

Is there a way in the WPF Toolkit datagrid to have a header below the column headers but above the first row

I looking for a way to create an area that indicates a user is at the top row of the WPF Toolkit datagrid. (Showing the scrollbar scrolled down is not enough for the user). I need something that sticks out and says "this is the top row" basically. Messing with the entities that that the grid is bound to will not work for me because I have several grids with different filters over the same collection of entities. Also this underlying collections is changing while the app is running.
Is there a way to add a control of some sort between the column headers and the first row of the datagrid? Maybe a separator of some sort?
Thanks!
Jon
A possible solution is to create your own Template for the column headers with ColumnHeaderTemplate and show whatever you need in there. This way you'll have full control of what your header looks like.
Another hackish solution could be you change the Style of the header to achieve the desired effect, like setting the bottom margin to a higher value so that there is a space between the header and the first row.

Resources