frmSample49.cs :  » GUI » SourceGrid » WindowsFormsSample » GridSamples » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » SourceGrid 
SourceGrid » WindowsFormsSample » GridSamples » frmSample49.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsSample.GridSamples{
    [Sample("SourceGrid - Extensions", 49, "Data Binding - DataGrid Custom entities data binding")]
    public partial class frmSample49 : Form
    {
        public frmSample49()
        {
            InitializeComponent();
        }

        public class Employee
        {
            private string mFirstName = "New";
            public string FirstName
            {
                get { return mFirstName; }
                set { mFirstName = value; }
            }

            private string mLastName = "New";
            public string LastName
            {
                get { return mLastName; }
                set { mLastName = value; }
            }

            private decimal mSalary = 800;
            public decimal Salary
            {
                get { return mSalary; }
                set { mSalary = value; }
            }

            private DateTime mBirthday = DateTime.Today;
            public DateTime Birthday
            {
                get { return mBirthday; }
                set { mBirthday = value; }
            }
        }

        private List<Employee> mEmployeeList = new List<Employee>();
        private DevAge.ComponentModel.BoundList<Employee> mBoundList;

        private void frmSample49_Load(object sender, EventArgs e)
        {
            Employee emp1 = new Employee();
            emp1.Birthday = DateTime.Today.AddYears(-18);
            emp1.FirstName = "Peter";
            emp1.LastName = "Parker";
            emp1.Salary = 3500;
            mEmployeeList.Add(emp1);

            Employee emp2 = new Employee();
            emp2.Birthday = DateTime.Today.AddYears(-38);
            emp2.FirstName = "John";
            emp2.LastName = "Smith";
            emp2.Salary = 2800;
            mEmployeeList.Add(emp2);

            mBoundList = new DevAge.ComponentModel.BoundList<Employee>(mEmployeeList);
            mBoundList.ListChanged += new ListChangedEventHandler(mBoundList_ListChanged);

            dataGrid1.Columns.Add("FirstName", "FirstName", 
                                typeof(string)).Width = 100;
            dataGrid1.Columns.Add("LastName", "LastName",
                                typeof(string)).Width = 100;
            dataGrid1.Columns.Add("Salary", "Salary",
                                new SourceGrid.Cells.Editors.TextBoxCurrency(typeof(decimal))).Width = 100;
            dataGrid1.Columns.Add("Birthday", "Birthday",
                                typeof(DateTime)).Width = 100;

            dataGrid1.DataSource = mBoundList;
        }

        void mBoundList_ListChanged(object sender, ListChangedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e.ListChangedType.ToString());
        }

        private void btViewNewEntities_Click(object sender, EventArgs e)
        {
            DevAge.ComponentModel.BoundList<Employee> changedList =
                    new DevAge.ComponentModel.BoundList<Employee>(mBoundList.AddedItems);

            changedList.AllowEdit = false;
            changedList.AllowNew = false;
            changedList.AllowDelete = false;

            gridChanges.DataSource = changedList;
        }

        private void btViewChangedEntities_Click(object sender, EventArgs e)
        {
            DevAge.ComponentModel.BoundList<Employee> changedList =
                    new DevAge.ComponentModel.BoundList<Employee>(mBoundList.EditedItems);

            changedList.AllowEdit = false;
            changedList.AllowNew = false;
            changedList.AllowDelete = false;

            gridChanges.DataSource = changedList;
        }

        private void btViewDeletedEntities_Click(object sender, EventArgs e)
        {
            DevAge.ComponentModel.BoundList<Employee> changedList =
                    new DevAge.ComponentModel.BoundList<Employee>(mBoundList.RemovedItems);

            changedList.AllowEdit = false;
            changedList.AllowNew = false;
            changedList.AllowDelete = false;

            gridChanges.DataSource = changedList;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.