Blogs

The Progress Bar - DevExpress XPF Blog

July 2010 - Posts

  • Silverlight Grid Control – Data Binding Series – Part 2

         

    In my previous post, I introduced the most common ways to bind an AgDataGrid control to a data source and provided a walkthrough of how to data bind using WCF RIA Services.

    This is the second post in the data binding series and here, I’ll take a look at how to use a WCF web service and LINQ to SQL classes to bind to the same SQL Server database.

    Binding to a SQL Server Express Database using a Web Service and LINQ to SQL Classes

    This example is assuming that you have a sample database running on a local SQL Server Express instance (“.\SQLEXPRESS”). If you do not have a database, the one used here will be attached at the end of the post, along with the completed project.

    Let’s start by creating a new Silverlight Application Project and a web application that will host it.

    New SL Project

    Next, right-click the web application project and add LINQ to SQL Classes to the project. Once created, the Object Relational Designer (the O/R Designer) is displayed. You can now establish a connection in the Server Explorer window of Visual Studio and drag and drop the desired tables onto the O/R Designer.

    OR Designer - DBML

    To make the LINQ class Serializable, click anywhere on the design surface and set the class’ Serialization Mode property to “Unidirectional”.

    Now let’s add the WCF Web Service to the project. Implement the interface as follows:

       1: namespace SilverlightGrid.Web
       2: {
       3:     [ServiceContract]
       4:     public interface IService1
       5:     {
       6:         [OperationContract]
       7:         List<Product> GetProducts();
       8:     }
       9: }

    The function can then be implemented in the Service1 class using the following code:

       1: public List<Product> GetProducts()
       2: {
       3:     DataClasses1DataContext db = new DataClasses1DataContext();
       4:     var products = from prod in db.Products select prod;
       5:     return products.ToList();
       6: }

    Rebuild the solution and add a service reference to the Silverlight application project.

    Add Service Reference

    Add an AgDataGrid control and bind it using the following code:

       1: using SilverlightGrid.ServiceReference1;
       2:  
       3: namespace SilverlightGrid {
       4:     public partial class MainPage : UserControl {
       5:         public MainPage() {
       6:             InitializeComponent();
       7:             ServiceReference1.Service1Client webService = new ServiceReference1.Service1Client();
       8:             // Sets up an event handler for the method that will be called when the GetCustomersCompleted event is raised. 
       9:             webService.GetProductsCompleted +=
      10:                 new EventHandler<ServiceReference1.GetProductsCompletedEventArgs>(webService_GetProductsCompleted);
      11:             // Makes the asynchronous call. 
      12:             webService.GetProductsAsync();
      13:         }
      14:         private void webService_GetProductsCompleted(object sender, ServiceReference1.GetProductsCompletedEventArgs e) {
      15:             agDataGrid1.DataSource = e.Result;
      16:         }
      17:     }
      18: }

    Rebuild and run the application and you’ll be presented with a DevExpress Silverlight Grid Control bound to the Products table of the local SQL Server Express Database.

    You can see the video demonstration of this tutorial on the DevExpress Channel: http://tv.devexpress.com/AgGridBindLINQtoSQL.movie

    The sample project and SQL database backup have been attached as a single zip file to this post.

  • Silverlight Grid Control - Data Binding Series – Part 1

         

    When using a grid control in your application, the first step is of course always to bind it to data. Now, using the Silverlight Data Grid Control, this is quite easy when loading data from a list at runtime. You can see a short video on the steps required to accomplish this here: http://tv.devexpress.com/AgGridBindRuntime.movie

    That route may be useful for small applications that need to display only a few rows of data, but that’s not a realistic scenario in which a grid is used most of the time. The more common scenario would be to bind the grid to a SQL Server database and to load records from a specified data table. Using functionality provided by the Silverlight platform and supported by DevExpress controls, it is possible to bind a grid control to a SQL Server data source in one of the following ways: WCF RIA Services, WCF Web Service + LINQ to SQL Classes, and finally, our own AgXPO Library. I’ll be demonstrating how to do each one as blog posts and videos accompanying them.

    Binding to a SQL Server Express Database using WCF RIA Services

    This example is assuming that you have a sample database running on a local SQL Server Express instance (“.\SQLEXPRESS”). If you do not have a database, the one used here will be attached at the end of the post, along with the completed project.

    So the first step would be to create a Silverlight Application Project and enable WCF RIA Services.

    New SL Project - WCF RIA Services

    Next, add a new ADO.NET Entity Data Model to the ASP.NET project that will host the Silverlight application. Select to generate the model from database, and from the desired database server, select the table that you’d like to use to populate the grid control. In this case, it’s the “Product” table from my sample database.

    Visual Studio - Entity Data Model

    Make sure you re-build the solution before proceeding further. Create a Domain Service Class and add it to the ASP.NET project. You’ll be asked to select the data contexts and the entities to be used in this domain service.

    New Domain Service Class  

    Once the class has been created, add an AgDataGrid control to the page and use the following C# and XAML code to bind it to the data and manually create the required columns.

       1: using System.ServiceModel.DomainServices.Client;
       2: using SilverlightGrid.Web;
       3:  
       4: namespace SilverlightGrid
       5: {
       6:     public partial class MainPage : UserControl
       7:     {
       8:         private ProductContext _productContext = new ProductContext();
       9:         public MainPage()
      10:         {
      11:             InitializeComponent();
      12:             LoadOperation<Product> loadOperation = _productContext.Load(_productContext.GetProductsQuery());
      13:             agDataGrid1.DataSource = loadOperation.Entities;
      14:         }
      15:     }
      16: }
       1: <dxg:AgDataGrid Name="agDataGrid1">
       2:     <dxg:AgDataGrid.Columns>
       3:         <dxg:AgDataGridColumn FieldName="ProductName"/>
       4:         <dxg:AgDataGridColumn FieldName="QuantityPerUnit"/>
       5:         <dxg:AgDataGridColumn FieldName="UnitPrice"/>
       6:         <dxg:AgDataGridColumn FieldName="UnitsInStock"/>
       7:         <dxg:AgDataGridColumn FieldName="UnitsOnOrder"/>
       8:         <dxg:AgDataGridColumn FieldName="Discontinued"/>
       9:     </dxg:AgDataGrid.Columns>
      10: </dxg:AgDataGrid>

    You can see the video demonstration of this tutorial on the DevExpress Channel: http://tv.devexpress.com/AgGridBindWCFRIA.movie

    The sample project and SQL database backup have been attached as a single zip file to this post.

  • End-User Layout Features of the WPF Pivot Grid Control

         

    The DXPivotGrid control is based on the award winning DevExpress Pivot Grid and Data Analysis technologies for the Windows Forms and ASP.NET platforms. The pivot grid provides advanced data mining and cross-tab reporting capabilities that can be easily integrated in your WPF applications.

    Of course, an OLAP drill down and data mining control shouldn’t just cater to the developer, but also provide the appropriate runtime functionality to make data analysis possible for end-users. Check out the following two videos that demonstrate some of the supported runtime functionality of the WPF Pivot Grid control.

    A demonstration of layout customization features available to end-users:

    WPF Pivot Grid - End-User Layout Features

    Runtime Sorting and Filtering functionality:

    WPF Pivot Grid - End-User Sorting and Filtering

  • Spell Checker Control for Silverlight (AgSpellChecker)

         

    The AgSpellChecker control is shipped as part of the DXperience Silverlight, DXperience Enterprise and DXperience Universal subscriptions. It is a lightweight, yet feature-complete control for providing spell checking functionality in your Silverlight applications.

    Some of the control’s features include:

    • Full support for DevExpress and Standard Silverlight Controls.
    • Support for Ispell, OpenOffice and custom dictionaries.
    • On-the-fly, “Check As You Type” setting
    • Microsoft Office Style Dialogs
    • And more...

    If you have already used our rich text editor control for Silverlight, you know of the built-in spell checking functionality. This feature utilizes AgSpellChecker’s integration with DevExpress controls to provide a seamless end-user experience.

    SL RichEdit SpellChecker

    The Spell Checker control can also be used to check the content of standard Silverlight controls. The implementation is quick and requires adding a few assembly references and typing a single line of code. To learn how to do that, check out the following short tutorial video:

    SL Spell Checker Video

  • Webcast: Using DevExpress Tools to Accelerate Business Development and Reporting

         

    Join me in an upcoming MSDN Webcast where we’ll go over the DevExpress Toolbox for Visual Studio 2010 and take a look at the integration, features and functionality provided by XtraReports, our advanced, end-to-end business reporting suite.

    Start Date:  Thursday, July 22, 2010 9:00 AM Pacific Time (US & Canada)

    Event Overview:

    For years, DevExpress has been enhancing and improving the developer experience by providing advanced technologies that include user interface controls, business application frameworks, object relational mapping, business reporting and analytics, and integrated development environment (IDE) productivity tools. Using DevExpress products throughout the project life cycle has proven to be a unified, cost-effective, and reliable solution. In this webcast, we explore the DevExpress product line, focusing on the reporting solution and the enhanced support for Microsoft Visual Studio 2010, Microsoft Silverlight, and Windows Presentation Foundation (WPF).


    You may register for the event using the following link: https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032454492&Culture=en-US

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.