How to create a GridView like view to the WPF ListView if i dont know the Column names at the design time because the collection will be created at runtime and the collection will be of type DataTable and it may contain a no.of columns.I can do it with WPF DataGrid but i want to achieve this with WPF ListView and I want to Achieve this without code behind.
You can add columns dynamically to a ListView by using Attached Properties. Check out this article on the CodeProject it explains exactly that...
WPF DynamicListView - Binding to a DataMatrix
Related
for an overview, an MVVM project in built in WPF.
Basically in my xaml, I have a datagrid bound to a dataview. When my service populates the dataview I get a dynamic table with an arbitrary number of columns.
For each column in the datagrid, I have created a headertemplate which contains a combobox which is bound to an Observable<Dictionary<string,BusinessEntity>> object as its item source in the xaml. Figuring out the combobox is another issue but I am trying to just populate data grid first, then worry about binding the combobox correctly.
anyways the only solution I have somewhat though of was to turn on autogeneratecolumn and then replacing all the headers with a combobox in the codebehind, but then I have issues trying to bind the combobox in the codebehind correctly and it doesn't feel MVVM if I have to create all those comboboxes there.
You can handle the AutoGeneratingColumn event to customize the auto generated column's header template.
I have a DataGrid that is displaying Data. I want to implement view switching functionality in WPF. I have read online and they say it's not possible with Data Grid .
There is also a topic that explains thumbnail view:
WPF: ListView with icons view?
But how to implement the same three view in the same control?
To be exact, I want the functionality like Windows Explorer where we can change the view from a dropdown list.
Some help in this regard would be great.
You are right. This is not something that the DataGrid supports. You can create your own views for the ListView, see the following article:
How to: Create a Custom View Mode for a ListView
I have an mvvm application...I need to have an editable listview.
I am binding my observable collection to listview.
How could I track changes of the values in listview ?...I mean if user edit an item...I need to have changed values in my observable collection.
If I use datagrid in WPFToolKit, is it easy ?
In a word, yes.
Take a look at data templates in WPF. They allow you to define how you want each item in your list (or any control) to appear and behave. So each item in your listview can one or more editable controls that are bound to each item in your collection (in this case an ObservableCollection). As you change data in the listview, the bound objects will in your collection will be updated in real time.
This is also possible with a datagrid.
Have a look at this link
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-3-in-place-edit
It is recommended you to use the Datagrid.It already provides the edit mode functionality. You can use a TemplateColumn to provide editing views.
if you have an editable Collection in your viewmodel, just take a datagrid(editable stuff built in). you can create styles or use templates so that the datagrid look the way you want.
If I use datagrid in WPFToolKit, is it easy ?
yes ;) but if you can, use the .net4 datagrid
I need to add a rowheader to a Listview GridView. it needs to act like a datagrid rowheader, sop it should be freezable.
is thsi possible? can anyone show me some source code to do this?
Thanks
The GridView do not have rowheaders but you can style the first column differently than the rest. Implementing freezing will require some innovative use of a scrollviewer. Can't you just use the DataGrid which has RowHeaders?
DataGrid Class
My application uses the WPF DataGrid control with custom columns. Although the property Columns is an ObservableCollection<>, the invocation of the method Move does not effect the order of the columns in any way.
Can I somehow reorder the columns of a WPF Toolkit DataGrid programmatically?
Best Regards
Oliver Hanappi
You can use the DisplayIndex property of a DataGridColumn (use datagrid.Columns to retrieve the columns collection).