b

blu

Saturday, 15 December 2012

DataGrid in SilverLight Example Vb.NET

DataGrid in SilverLight Example Vb.NET

        .Create a Silverlight  Project(including web application)

                      Silverlight 4, 5.
             .Add Datagrid and TextBlock to Grid Layout   as shown below

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid x:Name="LayoutRoot" Background="White">
        
<sdk:DataGrid AutoGenerateColumns="True" Height="221" HorizontalAlignment="Left" Margin="0,67,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="388" />
        <TextBlock FontSize="20" Foreground="Green" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="textBlock1" Text="Silverlight Data Grid Demo" VerticalAlignment="Top" Width="356" FontWeight="Bold" FontStretch="Condensed" TextWrapping="Wrap" />

    </Grid>
</UserControl>



  . Add a class called  Customers with the following properties,

   Public Class Customers        Public Property custID() As Integer
        End Property
        Public Property Name() As String
        End Property
        Public Property DOB() As DateTime
        End Property
        Public Property MemberSince() As DateTime
        End Property
        Public ReadOnly Property emailID() As String
        Get 
        }
        End Get
        End Property
 End Class


  .Fill  Customers List   with samples

Private  Sub FillData()
            custList.Add(New Customers 
            {
            custID=1, DOB=New DateTime(1973,12,12), emailID="p_pathi2020@yahoo.com", MemberSince=New DateTime(2000,12,12), Name="Peter hans" 
            }
)
            custList.Add(New Customers 
            {
            custID = 2, DOB = New DateTime(1970, 12, 12), emailID = "sam@yahoo.com", MemberSince = New DateTime(2000, 12, 12), Name = "sam benegal" 
            }
)
            custList.Add(New Customers 
            {
            custID = 3, DOB = New DateTime(1983, 12, 12), emailID = "paul@yahoo.com", MemberSince = New DateTime(2000, 12, 12), Name = "Paul hons" 
            }
)
            custList.Add(New Customers 
            {
            custID = 4, DOB = New DateTime(1993, 12, 12), emailID = "pari@yahoo.com", MemberSince = New DateTime(2000, 12, 12), Name = "whiteman pari" 
            }
)
            custList.Add(New Customers 
            {
            custID = 5, DOB = New DateTime(1988, 12, 12), emailID = "pron@yahoo.com", MemberSince = New DateTime(2000, 12, 12), Name = "Porn star" 
            }
)
End Sub

.Bind DataGird to Customer List

       Dim custList As List<Customers> =  New List<Customers>()         Private Function MainPage() As Public
            InitializeComponent()
            Me.Loaded += New RoutedEventHandler(MainPage_Loaded)
        End Function

        Private  Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            FillData()

            dataGrid1.ItemsSource = custList
        End Sub


.Here is the Output

No comments:

Post a Comment