ComponentOne DataGrid for WPF and Silverlight
DataGrid for WPF and Silverlight Overview / Getting Started / Quick Start / Step 2 of 4: Creating the Data Model
In This Topic
    Step 2 of 4: Creating the Data Model
    In This Topic

    In the last step you set up the grid application – but while the basic grid is functional, it contains no data. In this step you’ll add a data model to your project that you will later use to generate data to display in the C1DataGrid control.

    1. To add a data model, complete the following steps:
    2. Right-click the project node and select Add | Class….
    3. Name the class – Product.cs and click OK.
    4. Replace the generated Product class code with the following:
    C#
    Copy Code
    public class Product
    {
        static Random _rnd = new Random();
        static string[] _names = "Macko|Surfair|Pocohey|Studeby".Split('|');
        static string[] _lines = "Computers|Washers|Stoves|Cars".Split('|');
        static string[] _colors = "Red|Green|Blue|White".Split('|');
    
        public Product()
        {
            Name = _names[_rnd.Next() % _names.Length];
            Line = _lines[_rnd.Next() % _lines.Length];
            Color = _colors[_rnd.Next() % _colors.Length];
            Price = 30 + _rnd.NextDouble() * 1000;
            Cost = 3 + _rnd.NextDouble() * 300;
            Discontinued = _rnd.NextDouble() < .2;
            Introduced = DateTime.Today.AddDays(_rnd.Next(-600, 0));
        }
    
        public string Name { get; set; }
        public string Color { get; set; }
        public string Line { get; set; }
        public double Price { get; set; }
        public double Cost { get; set; }
        public DateTime Introduced { get; set; }
        public bool Discontinued { get; set; }
    }