using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ControlExplorer.FlexGrid
{
    public partial class DataAnnotations : C1DemoForm
    {
        public DataAnnotations()
        {
            InitializeComponent();

            flexGrid.DataSource = Data.GetSampleData(20);
        }
    }

    public class Data
    {
        // auto-generated CustomerName column header will show "Customer".
        // (even though the property name is "CustomerName")
        [System.ComponentModel.DataAnnotations.Display(Name = "Customer")]
        public string CustomerName { get; set; }

        // auto-generated CustomerID column will be invisible.
        [System.ComponentModel.DataAnnotations.Display(AutoGenerateField = false)]
        public int CustomerID { get; set; }

        // auto-generated "Frequency" column will show values formatted as percentages
        // and will not allow editing.
        [System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "0%")]
        [System.ComponentModel.DataAnnotations.Editable(false)]
        public double Frequency { get; set; }

        // create some sample data
        public static BindingList<Data> GetSampleData(int cnt)
        {
            var list = new BindingList<Data>();
            for (int i = 0; i < cnt; i++)
            {
                var item = new Data();
                item.CustomerName = string.Format("Customer {0}", i);
                item.CustomerID = i;
                item.Frequency = (i % 10) / 10.0;
                list.Add(item);
            }
            return list;
        }
    }
}
