The version that you requested is unavailable. We've redirected you to the latest version of the help.
Version

xamDataGrid Creating Of Sample ListCollectionView Code Example

Description

In code example below, the Utils class has a method called CreateDataSource, which returns ListCollectionView, populated with sample Item class objects. The Item class definition is available in the Item class code example.

Code

In Visual Basic:

Namespace ExternalOperations
      Public NotInheritable Class Utils
            Private Sub New()
            End Sub
            Public Shared Function CreateDataSource(itemCount As Integer) As IEnumerable
                  Dim items As New BindingList(Of Item)()
                  Dim r As New Random()
                  Dim now As DateTime = DateTime.Now
                  For i As Integer = 0 To itemCount - 1
                        Dim item As New Item() With {
                              .A = "a" & r.[Next](100),
                              .B = "b" & r.[Next](100),
                              .DateField = now.AddDays(r.[Next](100)).[Date],
                              .IntField = r.[Next](200),
                              .FloatField = CSng(r.NextDouble() * r.[Next](1000)),
                              .DoubleField = r.NextDouble() * r.[Next](1000),
                              .DecimalField = CDec(r.NextDouble() * r.[Next](1000))
                        }
                        items.Add(item)
                  Next
                  Dim lcv As New ListCollectionView(items)
                  Return lcv
            End Function
      End Class
End Namespace

In C#:

namespace ExternalOperations
{
    public static class Utils
    {
        public static IEnumerable CreateDataSource(int itemCount)
        {
            BindingList<Item> items = new BindingList<Item>();
            Random r = new Random();
            DateTime now = DateTime.Now;
            for (int i = 0; i < itemCount; i++)
            {
                Item item = new Item
                {
                    A = "a" + r.Next(100),
                    B = "b" + r.Next(100),
                    DateField = now.AddDays(r.Next(100)).Date,
                    IntField = r.Next(200),
                    FloatField = (float)(r.NextDouble() * r.Next(1000)),
                    DoubleField = r.NextDouble() * r.Next(1000),
                    DecimalField = (decimal)(r.NextDouble() * r.Next(1000))
                };
                items.Add(item);
            }
            ListCollectionView lcv = new ListCollectionView(items);
            return lcv;
        }
    }
}

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how to use external grouping with XamDataGrid .

This topic explains the external summary calculation feature of xamDataGrid and provides sample code to demonstrate its features.