Can one one please suggest me which one will be the best, fast and efficient method to fill a ListView in a WPF app.
From ObservableCollection or from DataSet?
Thanks.
I always go for ObservableCollection, I'd never use a DataSet bound directly to a control.
And if you are not changing the items in the collection, you should consider using List.
But with a little more info, maybe there would be good reason to use the dataset, but I don't think so.
Related
I'm creating a DataGrid in which I need to highlight one cell (textblock) based on whether one of several other cells (textboxes) in the same row gets focus. Not sure where to start with this. Any help would be appreciated.
Thanks.
There's a couple of ways you could approach something like this. The cleanest would be to add a property to your view model that you can bind to. A slightly messier way would be to bind all the properties involved via a MultiValueConverter.
I have a DataGrid and I need to add an Expander control dynamically to group few rows based on some conditions... Can anyone help me in this... I am completely new to Silverlight :(
Found the answer, I have created a separate column for the expander and managed to display it when my condition is satisfied. It is not dynamic though, but solved the purpose. :)
Dynamically--not sure what you want. I've done expanders statically. My two cents: keep it simple and don't try and do too much. If by dynamically you are taking about Master/Details data gridview, that can be done by XAML and loading the gridview with an ObservableCollection class (search the net). Also search for PagedCollectionView and .Visibility properties for controls. If you want to add controls to a StackPanel, dynamically, search the net for .Children.Remove methods.
Good luck, but as a beginner you are probably trying to do too much IMO.
I'm new to WPF and I haven't used MVVM yet but I think I'm in a situation where it might help.
In my program I've got several comboboxes that all have the same comboboxitems and when the user makes a selection in one of the comboboxes the selected comboboxitem gets disabled in the other comboboxes. (i.e. If the user has selected the comboboxitem with value 'a' in combobox #1 and selected the comboboxitem with value 'b' in combobox #2 then in remaining comboboxes both the comboboxitems with values 'a' and 'b' are disabled)
Anyway, I'm having trouble doing this programmatically in the code-behind and I was hoping someone could describe how to approach this problem using MVVM.
Thanks
MG
Here is one of the best primers on MVVM applied to WPF, with first rate code.
It isn't a quick read, and don't get frustrated if even seemingly simple things take some time to grok.
To answer your question more directly, you use MVVM to make data binding work (not to mention your logic testable). So for a ComboBox, you firstly supply it with data. probably using an ObservableCollection which has support for data binding in it. You can synchronize the Selected Item(s) in the ComboBox(es) to a property(ies) in your view model, and change the contents of one based on a change in the Selected Item.
Suggest you read that article and work through some code, then follow up with some more targeted questions using code.
HTH,
Berryl
I'm using LINQ to entities to insert and delete data from a DataGrid that is displayed on the homepage of my WPF application. I was wondering if there was a way or a DataGrid feature that would make my DataGrid auto-update and show changes upon insert/delete by itself rather than me having to re-execute the LINQ query that fills the datagrid (which is how i am achieving this now).
Thanks in advance.
Yes, bind your datagrid to an ObservableCollection<T>, or even better, to an Asynchronous Multi-threaded ObservableCollection...
This feels like a stupid question, but is there a simple control for WPF that just displays a collection of items? I am currently using a ListBox to display a collection of usercontrols, but the selection element is not needed and the highlighting is actually a distraction. I could disable the highlighting, but this seems like extra work if a simpler control exists. I don't need to track the selected item.
Basically, I want a stackpanel that I can just define an itemssource of viewmodels for. Does such a thing exist?
You can use an ItemsControl - it's pretty much exactly what you are looking for