CourseDataGridView.cs :  » Network-Clients » iReaper » IReaper » CourseData » 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 » Network Clients » iReaper 
iReaper » IReaper » CourseData » CourseDataGridView.cs
using System;
using System.Threading;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using WeifenLuo.WinFormsUI.Docking;

namespace IReaper.CourseData{
    public partial class CourseDataGridView : IReaper.BaseControl.RightClickableDataGridView
    {
        CourseCollection collection;
        Rectangle rec = Rectangle.Empty;

        public CourseDataGridView()
        {
            InitializeComponent();
            collection = new CourseCollection(CourseCollectionType.Common);
            Core.CoreData.PropertyChanged += new PropertyChangedEventHandler(CoreData_PropertyChanged);
            CourseXmlParser.OnBeforeCourseAdded += new EventHandler(BeforeCourseAdded);
        }

        public CourseDataGridView(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
            collection = new CourseCollection(CourseCollectionType.Common);
            Core.CoreData.PropertyChanged += new PropertyChangedEventHandler(CoreData_PropertyChanged);
        }

        protected override void OnSelectionChanged(EventArgs e)
        {
            base.OnSelectionChanged(e);
            Core.CoreData[CoreDataType.CurrentSelectedCourses] = this.GetSelectedCourses();
        }

        /// <summary>
        /// DataGridView
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void OnCellContextMenuStripNeeded(DataGridViewCellContextMenuStripNeededEventArgs e)
        {
            base.OnCellContextMenuStripNeeded(e);
            if (e.RowIndex < 0)
            { return; }
            //
            DataGridViewRow cRow = this.Rows[e.RowIndex];
            this.courseDataGridViewContextMenu.ContextCourse = cRow.DataBoundItem as Course;
            e.ContextMenuStrip = this.courseDataGridViewContextMenu;
        }

        protected override void OnDataError(bool displayErrorDialogIfNoHandler, DataGridViewDataErrorEventArgs e)
        {
            e.ThrowException = false;
            displayErrorDialogIfNoHandler = false;
            base.OnDataError(displayErrorDialogIfNoHandler, e);
        }

        private void BeforeCourseAdded(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new ThreadStart(delegate()
                {
                    this.BeforeCourseAdded(sender, e);
                }));
                return;
            }
            this.DataSource = null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private CourseCollection GetSelectedCourses()
        {
            //
            DataGridViewSelectedRowCollection allRows = this.SelectedRows;
            //
            collection.Clear();
            //
            foreach (DataGridViewRow r in allRows)
            {
                //Course
                Course item = r.DataBoundItem as Course;
                //
                if (item == null)
                { continue; }
                collection.Add(item);
            }
            return collection;
        }

        private void CoreData_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == CoreDataType.CurrentViewedCourses.ToString())
            {
                CourseCollection courses = Core.CoreData[CoreDataType.CurrentViewedCourses] as CourseCollection;
                if (courses != null)
                {
                    this.collection.Type = courses.Type;
                }
                this.DataSource = courses;
                //find parent form and activated it.
                DockContent parent = this.FindForm() as DockContent;
                if (parent != null)
                {
                    parent.Activate();
                }
            }
            else if (e.PropertyName == CoreDataType.CurrentFilteredCourses.ToString())
            {
                CourseCollection courses = Core.CoreData[CoreDataType.CurrentFilteredCourses] as CourseCollection;
                if (courses != null)
                {
                    this.collection.Type = courses.Type;
                }
                this.DataSource = courses;
                //find parent form and activated it.
                DockContent parent = this.FindForm() as DockContent;
                if (parent != null)
                {
                    parent.Activate();
                }
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.Button == MouseButtons.Left)
            {
                if (this.rec != Rectangle.Empty && !this.rec.Contains(e.X, e.Y))
                {
                    this.DoDragDrop(this.SelectedRows, DragDropEffects.Move | DragDropEffects.Copy);
                }
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            //Rect
            if(this.SelectedRows.Count == 0)
            { this.rec = Rectangle.Empty; }
            else//
            {
                this.rec = this.DisplayRectangle;
            }
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            this.rec = Rectangle.Empty;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.