I have a grid control in silverlight.I set up pagination for this control.Data is populated from db.I am trying to a sorting on all column headers.However sorting gets applied to specific page and does not apply to entire result set.How can this issue be fixed? Any suggesstions would be of great help.
Regards,
Pri
You can provide explicit IComparer implementations for the columns, as well as event handlers, to handle both questions.
Handle the click event on the header to resort your data however you like.
http://www.longhorncorner.com/UploadFile/nipuntomar/SortingDataSilverlightDataGrid09152008025951AM/SortingDataSilverlightDataGrid.aspx
And leverage the ICollectionView IComparer implementation to do the sorting of the HyperLinks
http://msdn.microsoft.com/en-us/library/system.windows.data.listcollectionview.aspx
(is the text of the hyperlinks all the same, e.g. ClickMe ?)
Also - since Silverlight is running on the client, has all the data been brought to it (or just that page's data, and paging is bringing data to the client)? eg what data source are you using? RIA Services and DomainDataSource? Or your own service calls?)
You might want to use PagedCollectionView. PagedCollectionView gives you lot of functionality out of the box without writing much code.You can use it to sort the data,filter the data,group the data.
Get your data from server in the way you prefer and create a PagedCollectionView with the object collection retrieved from the server and bind the datagrid with PagedCollectionView.
You can sort the data by adding SortDescriptions.
It is explained with examples at MSDN. Especially look for sort section.
Hope this helps.
Related
I want to bind data to a (Infragistics Silverlight) XamGrid.
The problem is that the content of the data source (columns and content itself) is variable and I only know it at run time.
I have implemented an ObservableCollection according to this web site
http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-via-idictionary/ to the silverlight datagrid, but it doesn't seem to work for the xamgrid.
Is it possible to implement a data source (ItemsSource in this case) with dynamic data?
What changes should I make to the solution presented in the web site, in order for it to work?
Thanks in advance.
If your objects are accessible with string indexers you can bind to them
http://help.infragistics.com/NetAdvantage/Silverlight/Current/CLR4.0/?page=xamGrid_Support_for_String_Indexers.html
Using ObservableCollections with Silverlight works great, because the UI is automatically updated when the data changes. But what if I am displaying a whole number of different views of the data, represented as different IEnumerable LINQ queries? My current approach is to have the DataContext implement INotifyPropertyChanged, and register for the backing collections CollectionChanged event, and fire the property changed event accordingly.
However, this is sort of repetitive to do over and over again. What I really want is an ObservableQuery that combines a query and an observable data source. Does this exist already? If not, what do I need to do when rolling my own for Silverlight to treat it the same way as an ObservableCollection? Is having a CollectionChanged event sufficient?
(I am most interested in Silverlight for the Windows Phone 7.)
What you describe doesn't really exist as such, but if you pass your IEnumerable<xx> into a CollectionViewSource (edit) you can get a few of the features decribed. This how ever does not fit so well with a ViewModel type pattern since you have to pull some leavers manually to make it work.
Another option is to take a quick look at the Reactive Framework. It's currently CTP (or maybe beta), but is also implemented for SilverLight. This gives you a LINQ querieable, IObservable<xx> Observable Stream or Collection (not to be confused with the ObservableCollection), that is basically an asynchronous, "push" version of IEnumerable .
It works very well with slow data loading into UI over a long period of time. You can can e.g. convert events into an observable stream, and start your LINQ query from there ect..
Check out this exellent Ch9 video w. Wes Dyer explaining how to use it with UI:
http://channel9.msdn.com/Blogs/J.Van.Gogh/Writing-your-first-Rx-Application
I have an old VB6 application. I want to recreate it in VB.Net using WPF. But I am a bit confused about the "Model View Controller"-pattern. I have two books about design patterns (GoF and J.Bishop) afair this pattern is indeed not mentioned inside one of the two books. I have also searched the internet I found some java-examples. But I have still no clue how I should use MVC-Pattern (should I?) in my new WPF-application.
Let's say for example my model (in fact it is more complex) is only a wheel rim (circle) with the properties Manufacturer, Diameter and Depth. The user should be able to modify the properties using textboxes and ComboBoxes.
Could somebody create a small example that explaines the MVC-Pattern with WPF?
Of course I like reusable classes to have a feasible concept throughout the whole application.
thanks in advance
Oops
Here's a "brief" description of what the MVC pattern is and how I would apply it to a WPF application.
(I might have a few details slightly off since I've mainy hacked in Silverlight but the concept is similar enough.)
Basically, the idea is to separate concerns and define interfaces between the different parts of an application, with the goal of keeping the code structured and maintainable.
The Model in your example would be pretty much exactly as you described the wheel rim - a WheelRim class with the various properties defined in suitable data types. I would put the model i an separate assembly to keep it apart from the other code, but you can settle for just keeping the model classes in a "Models" folder. The model would also have a "twin" in a database, the model classes being pretty much one-to-one-mapped to tables.
(You might wanna have a look at Linq2SQL or Entity Framework, if the database is defined you can pretty much get the model for free along with suitable database access code.)
The View would be the actual WPF xaml files - Defining the Grid or Canvas or what have you. On the WheelRimView there would be labels and textboxes for displaying or accessing the different properties, perhaps along with product images and the like. The code behind for the view would have all the relevant event handlers (start, button_click and so on) for getting the data from the fields and passing them to the controllers.
The Controller would be any "handler code" that you would use to manipulate the data. We're talking the basic CRUD operations here, along with validation and the like. Also, the controller layer would be responsible for compiling the data in a format that can go seamlessly into the View. The WheelRimController hence would have methods like "GetWheelRimList", "GetWheelRim", "AddWheelRim", "ModifyWheelRim" and "DeleteWheelRim". The methods take the values as in parameters and manipulate the model objects accordingliy. the
I would recommend keeping the code-behind of the xaml files free from any "controller"-ish code like validation, aggregation and the like - the code behind should basically only take the values from the textboxes, listboxes and such and send them on "as is" to the controller methods for processing. Also, you should keep any data formatting code to a minimum when getting data for presentation (i.e., no filtering or translating in the view).
A typical use case of "User opens a wheel rim and edits the diameter" would play out thus in code:
User clicks "Edit" on a list page. The WheelRimView page loads.
The WheelRimView.Load() method (or corresponding) calls WheelRimController.GetWheelRim(wheelRimId).
WheelRimController.GetWheelRim(wheelRimId) gets the corresonding data from a database table and populates the properties of a WheelRim object, which is returned to the WheelRimView.
The WheelRimView inserts the property values into the labels and textboxes.
The user changes the diameter value and clicks the "Save button.
The WheelRimView.Save() method calls the WheelRimController.ModifyWheelRimDiameter(wheelRimId, diameter) method.
The WheelRimController.ModifyWheelRimDiameter(wheelRimId, diameter) method parses the diameter (if it is a string) and loads the model object. It applies the modified value to the model object and saves it into the database.
The WheelRimController.ModifyWheelRimDiameter(wheelRimId, diameter) returns a status code to the WheelRimView (for instance a predefined numeric stating any validation errors) to report the success of the save.
The WheelRimView displays a result message (hopfully "saved") to the user.
I hope that clears a few bits up.
Bevcause of the rich binding support available, WPF (and Silverlight) are well suited to MVVM (Model-View-ViewModel). MVVM is an extension of MVC that uses a view model to bind the current state of a view, instead of manipulating the view directly.
There are a bunch of MVVM frameworks available, as well as Microsoft's own Prism framework (which is arguably more useful if you have a larger, modular application).
WPF is probably more well suited to MVVM (Model-View-ViewModel). I'd recommend reading this MSDN article on MVVM and, perhaps, following their advice. There's also a nice collection of links I found on the Bryant Likes blog.
I have a dataset which is about 3 million records, and I would like to load them in to a Data Grid within an application (WinForm).
What is the best approach / method of displaying the data.
I need to be able to run a filter to the data to reduce down the data set, ideas would be welcomed
A good idea would be filtering the data in the database and retrieving only the (pre)filtered result set. If this set is still large, use virtual mode, but also rethink your design - if you want to display so much data, that you are getting into performance problems, you might be showing to much data for a user, too.
In addition to filtering you should also consider paging in the backend (your SP should handle paging)
You can bind the grid to the DataSet, using the DataSource property and a BindingSource component. The Forms designer can take care of the creation of the BindingSource for you.
The BindingSource has a Filter property that allows you to filter the content of the DataSet
EDIT: by the way, in data-bound mode, the DataGridView implicitly uses virtual mode, so you don't have to worry about having too many rows in the grid
I have a WPF ListBox that I would like to add pagination to as it starts getting slow with a bunch of items. My problem is that I use the Grouping, Sorting, and Filtering. That means if I were to limit the data with the LINQ Skip() and Take() methods or using something like a paginated ObservableCollection the grouping and sorting would be wrong because it would only be applied to the first page of data. Filtering would be even worse because it would just filter the data displayed in the current display which would mean you would have to be on the page that it would show up on to be able to search for it.
I'm not too keen on the idea of rewriting all of that logic. I see Silverlight 3 is getting a PagedCollectionView (but as far as I can tell WPF in .NET 4 is not getting it). Has anyone implemented something like this before or have any ideas on how I should solve this?
Check out a simple Paginated ObservableCollection I have implemented - works for Silverlight as well as WPF
http://jobijoy.blogspot.com/2008/12/paginated-observablecollection.html