Wednesday, September 9, 2009

Working with Silverlight 3's DataPager Control

Silverligth 3's DataPager control works great if you are working with the .Net Ria Services. The .Net Ria Services make it easy for you to retrieve data from a db and page it so it is not all retrieved at once (improving performance). But how do you use the control if you want to manually create it yourself? What if you already have your paging scheme implemented and all you wish to do is use a new pager control?

This is relatively simple to do, but it isn't the most elegant code. You will need to use a PagedCollectionView. This is what you have to set the source to in your pager in order to get it to work. In order to use this class, you will need to add the following using statement to your source file.

using System.Collections.Specialized;

Once you have that, you can create a PagedCollectionView by passing an array to the constructor. In this example, I have an integer array (pagerSource) which is filled with a bunch of 1's. You could really put whatever you want in here. You can make it any type of array too, I just chose and integer one. Once I have my array the appropriate length (length will equal the pager's # of pages), I can create the PagedCollectionView object and set that as the source of my pager. I can then assign event handlers as you would expect to see when the pageIndex changes and perform my logic accordingly.

Enjoy!

int totalPages =  .//... logic to figure out my # of pages

int[] pagerSource = new int[totalPages];
for (int i = 0; i < totalPages; i++)
{
     pagerSource[i] = 1;
}

pagedCollectionView = new PagedCollectionView(pagerSource);
myPager.Source = pagedCollectionView;

Thursday, September 3, 2009

This Saved My Neck!

Just a quick post in case you are ever in the situation I was in today. I was told to have a presentation ready in a couple of days to present to management in our company. Great. I have had those materials prepared for a while, so all I have to do is tweak them a bit and I'm ready to go... WRONG! I somehow lost all my files. The directory where I had my presentation saved vanished!!!

I searched for a while for applications to recover my deleted files. I found a few that looked ok, so I downloaded the trials. I started searching my pc, but it was taking forever (and I did not have that kind of time). I finally remembered a Vista commercial that briefly mentioned something about how easy Vista makes it to recover deleted files, so I started searching for that. With that search I found ShadowExplorer. Now, the first post I saw on it mentioned that it was built in to all of the versions of Vista, but I did not see it in mine (Vista Business). I searched for a download of it and found this site...

http://forums.techarena.in/tips-tweaks/1063644.htm

From there, I was able to download the latest version and recover my files with just a few clicks of the mouse!!!

ShadowExplorer is a life-saver, so I thought I'd share in case anyone else finds themselves in a similar conundrum.

Enjoy!!!!