BrainDump
  Home arrow BrainDump arrow Page 6 - Introduction to Binding ComboBox and DataG...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Introduction to Binding ComboBox and DataGrid Controls in Silverlight 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-02-04

    Table of Contents:
  • Introduction to Binding ComboBox and DataGrid Controls in Silverlight 2.0
  • Developing WCF Service to serve Business (Entity) Objects collection using LINQ to SQL
  • Binding Object Collections Silverlight 2.0 ComboBox control dynamically
  • Binding Object Collections to cascading Silverlight 2.0 ComboBoxes
  • Binding Object Collections to Silverlight 2.0 ComboBox cascading with DataGrid
  • Detailed Explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to Binding ComboBox and DataGrid Controls in Silverlight 2.0 - Detailed Explanation


    (Page 6 of 6 )

    Let us try to understand the code in the previous sections:

    Binding Dropdown to Object Collection:

    We are consuming the WCF service with the following statements:


    Dim objService As New EmpService.EmpServiceClient

    objService.GetDepartmentListAsync()


    As the communication takes place in an asynchronous manner, the "DeptListFetched” method gets executed when the fetching is completed. This callback mechanism is managed by using delegation as follows:


    AddHandler objService.GetDepartmentListCompleted, AddressOf DeptListFetched


    The “DeptListFetched” method gets executed by the Silverlight framework once the WCF service responds. The “GetDepartmentList” method sends back a collection of objects and gets directly filled into “GetDepartmentListCompletedEventArgs” (in this case, it is the “e” parameter in “DeptListFetched” method). Finally, we assign the same to the ComboBox as follows:


    Private Sub DeptListFetched(ByVal sender As Object, ByVal e As EmpService.GetDepartmentListCompletedEventArgs)

    Me.cboDept.DisplayMemberPath = "Dname"

    Me.cboDept.ItemsSource = e.Result

    End Sub


    Cascading Dropdowns with Object Collection binding:

    This works very similar to the binding dropdown, except that the second dropdown gets bound every time when the user selects an item in the first drop down.

    You can observe the following event, which fetches employee information from the WCF service based on the user-selected department (in the first ComboBox):

    Private Sub cboDept_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles cboDept.SelectionChanged

    Me.lblMsg.Text = "Fetching Employees.."

    Dim oDept As EmpService.Dept = Me.cboDept.SelectedItem

    objService.GetEmployeeListByDeptAsync(oDept.Deptno)

    End Sub


    The second dropdown gets bound to the list of employees during callback, as shown in the following code:


    Private Sub EmpListFetched(ByVal sender As Object, ByVal e As EmpService.GetEmployeeListByDeptCompletedEventArgs)

    Me.cboEmp.DisplayMemberPath = "Ename"

    Me.cboEmp.ItemsSource = e.Result

    Me.lblMsg.Text = "Fetched!"

    End Sub



    In my upcoming articles, we will see more and more examples of Silverlight 2.0 development together with LINQ to SQL and WCF. I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hai,This is my next article in the series focusing on Siverlight 2.0 tutorials. ...
     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek