Nov 2, 2010

How to bind WinGrid to obtain a card view layout - Infragistics

This code shows how to obtain a card view layout with the help of Infragistics WinGrid. WinGrid helps you to easily print and export your data in the form of excel or PDF document.

1. Bind grid to a DataSource (Same as we do in usual Gridview)
wingrid1

2. Now we need to obtain a card view layout which can be achieved by properties of Displaylayout object

VB:


'You must set this property in order to print in card view.
Me.UltraGrid1.DisplayLayout.AllowCardPrinting = _
   Infragistics.Win.UltraWinGrid.AllowCardPrinting.RootBandOnly

'Display WinGrid in card view.
Me.UltraGrid1.DisplayLayout.Bands(0).CardView = True

'Set a caption for each card using the CompanyName field.
Me.UltraGrid1.DisplayLayout.Bands(0).CardSettings.CaptionField = "CompanyName"


C#:
//You must set this property in order to print in card view.
this.ultraGrid1.DisplayLayout.AllowCardPrinting = Infragistics.Win.UltraWinGrid.AllowCardPrinting.RootBandOnly;

//Display WinGrid in card view.
this.ultraGrid1.DisplayLayout.Bands[0].CardView = true;

//Set a caption for each card using the CompanyName field.
this.ultraGrid1.DisplayLayout.Bands[0].CardSettings.CaptionField = CompanyName";


3. To print cards (print layout) you need to write code in InitializePrintPreview event
VB:
'Standard labels makes it easier for each card to stand on its own, allowing you 'to possibly cut out the cards for distribution.
e.PrintLayout.Bands(0).CardSettings.Style = _ Infragistics.Win.UltraWinGrid.CardStyle.StandardLabels

'Setting the MaxCardAreaCols and MaxCardAreaRows properties allow you to limit 'the amount of cards per page. Setting these properties to 3 will give you nine 'cards per page.
e.PrintLayout.Bands(0).CardSettings.MaxCardAreaCols = 3
e.PrintLayout.Bands(0).CardSettings.MaxCardAreaRows = 3

'Each card will automatically increase width in order to fit in the available space.
e.PrintLayout.Bands(0).CardSettings.AutoFit = True
C#:
//Standard labels makes it easier for each card to
//stand on its own, allowing you to possibly cut out the cards for distribution.
e.PrintLayout.Bands[0].CardSettings.Style = Infragistics.Win.UltraWinGrid.CardStyle.StandardLabels;

//Setting the MaxCardAreaCols and MaxCardAreaRows properties allow you to limit //the amount of cards per page. Setting these properties to 3 will give you nine //cards per page.
e.PrintLayout.Bands[0].CardSettings.MaxCardAreaCols = 3;
e.PrintLayout.Bands[0].CardSettings.MaxCardAreaRows = 3;

//Each card will automatically increase width in order to fit in the available space.
e.PrintLayout.Bands[0].CardSettings.AutoFit = true;
4. For print preview write this code on the button click event of Print Preview
VB:
'Calling the PrintPreview method displays WinGrid's print preview dialog box.
Me.UltraGrid1.PrintPreview()
C#:
//Calling the PrintPreview method displays WinGrid's print preview dialog box. this.ultraGrid1.PrintPreview();


5. Now Run the application and you'll see the output in the form of card view.
wingrid2

6. Output on Print Preview
wingrid3

No comments:

Post a Comment