I'm trying to achieve a view similar to this ((Sub)(Sub)Item names not being part of the view - they show how the source data is structured):
EDIT:
As per comment, I'm adding an example of how I want to render the data (2 items):
That is, I have bunch of Items which I want to render in customized way. Those have SubItems that start being part of the grid (possibly spanning multiple cells). And those have SubSubItems with more data to put inside the grid (each on one row).
I want the data that belongs to a grid, to be aligned according to my Column headers.
I manged to make this work using a ListBox with ItemTemplate set to DataTemplate defined in resources. Going down 3 levels of hierarchy, using Grids to layout the content. There were 2 issues with this:
Aligning the data in grid with column headers. I managed to solve this using top level grid as column headers and IsSharedSizeScope/SharedSizeGroup. But it wasn't very nice solution and the alignment proved difficult to achieve.
Drawing borders around cells - since it wasn't just one Grid, but multiple within each other, borders would not connect nicely or have different thickness. I didn't manage to solve this so far.
I tried using ListView instead of ListBox, with GridViewColumn, but that disabled the ItemTemplate rendering.
Is there a way to use both? Or some other way to add the Columns with their default nice style and on-the-fly re-sizing capabilities? What about the cell borders?
Or am I looking at it entirely wrong and I should use different approach altogether?
I did try using DataGrid but that seemed even worse approach.
Note: I need virtualization - working with lots of items.
Related
I have a list of Grids with several rows and columns containing StackPanels. Each stack panel contains one or more Image objects, in some cases none at all and some Borders.
I would like to save these Grids to a file(sort of save functionality) and later get it back into memory and display it again.
What would be the best approach? Is there a way to do this operation in a simple way, or should I add every important data to the file, like the row and column count, StackPanel count, and how many Image objects are they having and each image with their position in the StackPanel and so on?
Edit:
These Grid objects are created and managed completely in code-behind.
I use the MVVM pattern throughout the project.
(in case these are important to informations)
I have a StackPanel of Datagrids that contain data about various things. A user should be able to click on one of those datagrids and that datagrid should expand and take the place of the four datagrids on the screen. Clicking on the expanded grid should return the screen back to the previous display of four data grids.
I have tried replacing the top grid in the backend (I don't think this is a violation of MVVM since it is dealing purely with the display, but I could be wrong) with the selected grid, which doesn't seem to work. I have also tried hiding the grids to see if that would work. I found several topics here and elsewhere talking about moving columns and/or rows around at runtime, but nothing about moving an entire datagrid at runtime.
I would suggest building your UI view as a grid with column/row sizes bound to match their content, and use a backend property to determine whether the various datagrids should be Visible or Collapsed as a result of your clicking. Then the UI will adapt to fit the scenario you want.
Another alternative is to have a couple of views which have the explicit arrangement of controls you want, then have an outer ContentControl whose Content property is changed to one or the other as a result of the clicks.
I'd favour the former though for simplicity if feasible in your layout.
In the .Net 4.0 WPF Datagrid, the edit mode of a DataGridComboBoxColumn pops up the ComboBox drop-down in a size that is not dependent on the size of the cell containing the data.
I am building a template for a cell that is somewhat like a combobox, but has features like multi-select, other controls as collaborating neighbors, etc. My editor is working nicely, except for one issue.
I've been trying to figure out how to make the editor appear in front of the DataGridCell that is being edited, and not limited to the current size of that cell, so that the control can be large enough to present content and behaviors nicely to the user. This is similar to what the drop-down of the combobox cell does in WPF data grid.
Can anyone tell me how to do that?
Thanks in advance...
ComboBoxes use Popups, you could put your control in one (presumably only when editing -> Put one in the CellEditingTemplate).
I am quite new to WPF and XAML but my background is of ASP.NET and C# so I have a vague idea of how it works.
In .net, I can use the repeater, datalist, gridview, bind to them a DataTable and output from that DataTable. I am now wanting to do the same with WPF.
Basically, I want to display simple records from a database (preferably using a DataTable as I usually work with those). The list might be something like this with two columns
1) Grey TV
2) Red car
3) Blue motorbike
I have looked around but I can't get a definitive answer on what control to use. Some people say ItemsControl and some people say DataGrid. Can anyone help me here?
Thanks in advance.
A DataGrid is used for displaying Table-like data (Per record multiple columns). An ItemsControl is used to display data using your own ItemTemplate, in which you are unlimited in how to represent the items and in what directions or alignments.
Another good useable control for you might be a ListView, which works just as a ListBox except it doesn't have any selection logic. And you can choose between four different ways of displaying your items using the View property (http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx).
In your case I would suggest using a ListView.
To bind any items to the control, you have to set the DataContext on the UserControl or the Control itself. And then bind the ItemsSource property to a local List or Collection using the Binding markup extension (http://msdn.microsoft.com/en-us/library/ms750413.aspx). To learn more about data-binding go here:
http://msdn.microsoft.com/en-us/library/ms752347.aspx
I have an application (winforms, c#) that displays data in a Listview in a very usual way - the first row is headers, the first column in each row is header and the following sub-items is the data itself.
I want the first column (the headers columns) always visible and the horizontal scroll to affect the other columns only.
i don't think it is possible in winforms listview (am i wrong?). Hence, i'm thinking to split the listview to two listviews - one for headers and the second for data. In that case, i need to connect the vertical scroll bars - a task which i find to be harder than i've expected.
Am i taking a wrong path (e.g. would it be easier to use a different control)?
If not, any pointers on how to implement it?
Note: Winforms Listview has poor API (e.g. no scrolling event) and is known as buggy, so i'm looking a working sample rather than MSDN links...
Thanks
As already noted the DataGridView supports this behaviour, but nobody told how this will be done:
To enable this feature simply set the Frozen property of a column. Further informations can also be found in this How to: Freeze Columns in the Windows Forms DataGridView Control.
I think you have to try to use the DatagridView instead of the listbox. As far as I know, the DataGridView supports this.
Did you try using DataGridView instead?
Edit:
In case you run into problems with setting row headers text, take a look at this post (basically, you set row header text upon item being added to grid).