frmSample51.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 » frmSample51.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 - Advanced features", 51, "Nullable CheckBox and OnValueChanged Controller")]
    public partial class frmSample51 : Form
    {
        public frmSample51()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            grid1.Redim(30, 2);

            grid1[0, 0] = new SourceGrid.Cells.ColumnHeader("Checked");
            grid1[0, 1] = new SourceGrid.Cells.ColumnHeader("CheckStatus");

            SourceGrid.Cells.Editors.ComboBox combo = new SourceGrid.Cells.Editors.ComboBox(typeof(DevAge.Drawing.CheckBoxState));

            DependencyColumn boolToStatus = new DependencyColumn(1);
            boolToStatus.ConvertFunction = delegate(object valBool)
                                            {
                                                if (valBool == null)
                                                    return DevAge.Drawing.CheckBoxState.Undefined;
                                                else if ((bool)valBool == true)
                                                    return DevAge.Drawing.CheckBoxState.Checked;
                                                else
                                                    return DevAge.Drawing.CheckBoxState.Unchecked;
                                            };

            DependencyColumn statusToBool = new DependencyColumn(0);
            statusToBool.ConvertFunction = delegate(object valStatus)
                                            {
                                                DevAge.Drawing.CheckBoxState status = 
                                                    (DevAge.Drawing.CheckBoxState)valStatus;

                                                if (status == DevAge.Drawing.CheckBoxState.Undefined)
                                                    return null;
                                                else if (status == DevAge.Drawing.CheckBoxState.Checked)
                                                    return true;
                                                else
                                                    return false;
                                            };

            for (int r = 1; r < grid1.RowsCount; r++)
            {
                grid1[r, 0] = new SourceGrid.Cells.CheckBox(null, null);
                grid1[r, 0].Editor.AllowNull = true;
                grid1[r, 0].AddController(boolToStatus);

                grid1[r, 1] = new SourceGrid.Cells.Cell(DevAge.Drawing.CheckBoxState.Undefined, combo);
                grid1[r, 1].AddController(statusToBool);
            }

            grid1.AutoSizeCells();
        }

        class DependencyColumn : SourceGrid.Cells.Controllers.ControllerBase
        {
            private int mDependencyColumn;
            public DependencyColumn(int dependencyColumn)
            {
                mDependencyColumn = dependencyColumn;
            }

            public delegate object ConvertDelegate(object source);
            public ConvertDelegate ConvertFunction;

            public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
            {
                base.OnValueChanged(sender, e);

                //I use the OnValueChanged to link the value of 2 cells
                // changing the value of the other cell

                SourceGrid.Position otherCell = new SourceGrid.Position(sender.Position.Row, mDependencyColumn);
                SourceGrid.CellContext otherContext = new SourceGrid.CellContext(sender.Grid, otherCell);

                object newVal = sender.Value;
                if (ConvertFunction != null)
                    newVal = ConvertFunction(newVal);

                if (!object.Equals(otherContext.Value, newVal))
                    otherContext.Value = newVal;
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.