Thursday, August 27, 2009

DevWeek 2009 Slides And Source Code - Guy Smith

You can find the slides and source code for DevWeek 2009 presentations on 23rd March 2009 here:-

Saturday, August 1, 2009

Silverlight 3 DataGrid Columns Grouping using PagedCollectionView

In this post I am showing how to implement Column Grouping in SIlverlight 3 DataGrid,

Before starting make sure you have SIlverlight3_Tools installed in your system, not SIlverlight 3 Beta, as there are lost of changes in Grouping of Columns from SIlverlight 3 Beta to Silverlight 3 RTW.


You can follow the few simple steps below to get the Grouping for your Silverlight 3 DataGrid.

Else you can also download the code demonstrated from here.

1. Create an Silverlight Application using you Visual Studio 2008 IDE, and add a hosting web application in the project.

2. Once you have done with this, you will get an two projects in your Solution, you need to code only in your silverlight project.

3. Now add a C# class file called Person.cs in your Silverlight Project. This class is used to provide some sample data to Silverlight DataGrid, you can change this to your other datasources like SQL, XML, etc.

I have added the following lines of code in Person.cs

   1: public class Person
   2:     {
   3:         public string FirstName { get; set; }
   4:         public string LastName { get; set; }
   5:         public string City { get; set; }
   6:         public string Country { get; set; }
   7:         public int Age { get; set; }
   9:         public List<Person> GetPersons()
  10:         {
  11:             List<Person> persons = new List<Person>
  12:             {
  13:                 new Person
  14:                 { 
  15:                     Age=32, 
  16:                     City="Bangalore", 
  17:                     Country="India", 
  18:                     FirstName="Brij", 
  19:                     LastName="Mohan"
  20:                 },
  21:                 new Person
  22:                 { 
  23:                     Age=32, 
  24:                     City="Bangalore", 
  25:                     Country="India", 
  26:                     FirstName="Arun", 
  27:                     LastName="Dayal"
  28:                 },
  29:                 new Person
  30:                 { 
  31:                     Age=38, 
  32:                     City="Bangalore", 
  33:                     Country="India", 
  34:                     FirstName="Dave", 
  35:                     LastName="Marchant"
  36:                 },
  37:                 new Person
  38:                 { 
  39:                     Age=38,
  40:                     City="Northampton",
  41:                     Country="United Kingdom", 
  42:                     FirstName="Henryk", 
  43:                     LastName="S"
  44:                 },
  45:                 new Person
  46:                 { 
  47:                     Age=40, 
  48:                     City="Northampton", 
  49:                     Country="United Kingdom", 
  50:                     FirstName="Alton", 
  51:                     LastName="B"
  52:                 },
  53:                 new Person
  54:                 { 
  55:                     Age=28, 
  56:                     City="Birmingham",
  57:                     Country="United Kingdom",
  58:                     FirstName="Anup", 
  59:                     LastName="J"
  60:                 },
  61:                 new Person
  62:                 { 
  63:                     Age=27,
  64:                     City="Jamshedpur",
  65:                     Country="India", 
  66:                     FirstName="Sunita", 
  67:                     LastName="Mohan"
  68:                 },
  69:                 new Person
  70:                 { 
  71:                     Age=2, 
  72:                     City="Bangalore", 
  73:                     Country="India", 
  74:                     FirstName="Shristi", 
  75:                     LastName="Dayal"
  76:                 }
  77:             };
  79:             return persons;
  80:         }
  81:     }

4. Now since my data is ready, I will add the DataGrid control in my XAML page, to make the presentation more attractive, I have added few more lines of code.

5. I have also added a ComboBox Control to Select the Grouping Columns name.

My XAML code will look something like this below.

   1: <UserControl 
   2:     xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
   3:     x:Class="Silverlight3DataGrid.MainPage"
   4:     xmlns="" 
   5:     xmlns:x=""
   6:     xmlns:d="" 
   7:              xmlns:mc="" 
   8:     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
   9:     <Grid x:Name="LayoutRoot">
  10:         <Grid.RowDefinitions>
  11:             <RowDefinition Height="0.154*"/>
  12:             <RowDefinition Height="0.483*"/>
  13:             <RowDefinition Height="0.362*"/>
  14:         </Grid.RowDefinitions>
  16:         <StackPanel Orientation="Horizontal">
  17:             <TextBlock Text="Select Sort Criteria" 
  18:                        VerticalAlignment="Center" />
  20:             <TextBlock Text="    " />
  22:             <ComboBox Grid.Row="0" 
  23:                       HorizontalAlignment="Left" 
  24:                       Width="200" 
  25:                       Height="30" x:Name="SortCombo" 
  26:                       SelectionChanged="SortCombo_SelectionChanged">
  28:                 <ComboBoxItem Content="Country" ></ComboBoxItem>
  29:                 <ComboBoxItem Content="City" ></ComboBoxItem>
  30:                 <ComboBoxItem Content="Age" ></ComboBoxItem>
  31:             </ComboBox>
  32:         </StackPanel>
  34:         <data:DataGrid x:Name="PersonGrid" Grid.Row="1"></data:DataGrid>
  36:     </Grid>
  37: </UserControl>

6. Now as my Data and Presentation is ready, its time for me to write some lines of code to Retrieve my sample data, group them into columns and then Bind it to the Grid.

Please find below the rest of the Code which demonstrates how I have Grouped the Columns using PagedCollectionView and PropertyGroupDescription.

   1: public partial class MainPage : UserControl
   2:     {
   3:         PagedCollectionView collection;
   5:         public MainPage()
   6:         {
   7:             InitializeComponent();
   8:             BindGrid();
   9:         }
  11:         private void BindGrid()
  12:         {
  13:             Person person = new Person();
  14:             PersonGrid.ItemsSource = null;
  15:             List<Person> persons = person.GetPersons();
  16:             collection = new PagedCollectionView(persons);
  17:             collection.GroupDescriptions.Add(new 
  18:                 PropertyGroupDescription("Country"));
  20:             PersonGrid.ItemsSource = collection;
  21:         }
  23:         private void SortCombo_SelectionChanged(object sender, 
  24:             SelectionChangedEventArgs e)
  25:         {
  26:             ComboBoxItem person = SortCombo.SelectedItem as ComboBoxItem;
  27:             collection.GroupDescriptions.Clear();
  28:             collection.GroupDescriptions.Add(new 
  29:                 PropertyGroupDescription(person.Content.ToString()));
  31:             PersonGrid.ItemsSource = null;
  32:             PersonGrid.ItemsSource = collection;
  33:         }
  34:     }

Yes its that simple, and its done. I know I have not given much description here, because nothing much to explain here. In the code above I am loading the Grid with my sample data coming from my Person class and default grouping the Person with Country.

Later on SortCombo_SelectionChanged, I am dynamically fetching the Selected column names from the ComboBox and Sorting on that.

Once you will run this application the screen will look something like this as given below.

Grouped by Country


Grouped by City


 Grouped by Age



You can group according to your requirement, like Grouping Active and Deleted items, etc.


You can also download the sample code from here.

I know the code here is not very well formatted, you can also refer the following location for the more better formatted version.

Silverlight 3 DataGrid Columns Grouping using PagedCollectionView




Sunday, July 26, 2009

FREE Cheat Sheets for Developers(Quick Reference Card)

Hi All, here is the link for the great library of cheat sheets, I assure you that after looking into this collection you will be amazed....these Cheat Sheets are...

  • Written by bestselling authors and leading experts
  • Reliable information on major developer topics
  • Filled with useful tips and source code examples
  • PDF looks great on-screen or printed from your printer

To name a few...

  • Design Patterns
  • Silverlight 2, I am eagerly waiting for Silverlight 3, I know its too early...
  • C#
  • Core .NET
  • Core ASP.NET
  • Scrum
  • Windows PowerShell

These are just few of my interest, but you can always register and logon to download lot more of your interest too...from the link below.

Saturday, July 25, 2009

Everything you need to get started...MOSS 2007, WSS 3.0

This is a hub for SharePoint 2007 and WSS 3.0 Resources with two advantages: All resources are hand-picked and vetted for quality, and each topic contains a with hand-tuned search designed to return the latest content which you can then filter further to find what you need.

Eli's SharePoint 2007 Resources

Thursday, July 23, 2009

Sharing source code between .NET and Silverlight

A common problem when developing Silverlight applications is how to share classes and in particular (Entity Framework) entities which are compiled for the full .NET framework in a Silverlight application. Silverlight is a browser plugin and a platform independent subset of the full .NET framework. Therefore Visual Studio does not allow referencing .NET assemblies from your Silverlight application.

Fortunately there is a very simple technique to share and reuse source code. Full details of which you can find in the link below

In this article Stefan Cruysberghs demonstrated this technique with several real world examples and I will give you some handy tips.

This linked has helped me, as I have SOA, where WCF Services, DataContracts, ServiceContracts are shared between my ASP.NET , WPF and Silverlight application.

Monday, July 20, 2009

Migration from Silverlight 2.0 to Silverlight 3

As currently I am working on Migration from Silverlight 2.0 to Silverlight 3, so I thought to share or bookmark few of the important links which I am going through.

Find below the links

Silverlight 3 Released! What is new/changed?


The following list encompasses all changes made between the Silverlight Toolkit March 2009 release and the Silverlight Toolkit July 2009 release.

Silverlight Toolkit July 2009 changes


The following list encompasses all change made between the Silverlight Toolkit December 2008 release and the Silverlight Toolkit March 2009 release.

Silverlight Toolkit March 2009 change list.


In the process of upgrade there are few more challenges I am going to face

Upgrade of my WCF Services to implement Silverlight 3 Validation controls, as my DataContract is residing in Service Layer, and I am using WSSF to generate the WCF DataContract, ServiceContract, etc. As all the DataCOntracts are AutoGenerated so implementing the Validation in Silverlight will be bit tricky.

Since I still I am in the process of upgrade, so if you too have some good links which will help me to upgrade my Services as I mentioned above then please do share here.



Brij Mohan