GrapeCity CalendarGrid for Windows Forms 2.0J
CurrentCellPositionChanging イベント
使用例 

アクティブセルの位置が変更される前に発生します。
構文
Public Event CurrentCellPositionChanging As EventHandler(Of CalendarCellPositionChangingEventArgs)
public event EventHandler<CalendarCellPositionChangingEventArgs> CurrentCellPositionChanging
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、CalendarCellPositionChangingEventArgs 型の引数を受け取りました。次の CalendarCellPositionChangingEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
Cancel System.ComponentModel.CancelEventArgsから継承されます。
MoveStatusCurrentCellPositionChanging イベントを発生させた動作を示すステータスを取得します。  
NewCellPosition新しい CurrentCellPosition を取得または設定します。  
OldCellPosition古い CurrentCellPosition を取得します。  
解説
ターゲット位置への変更をキャンセルし、アクティブセルを他の任意の位置にリダイレクトできます。
使用例
次のサンプルコードは、アクティブセルの位置をリダイレクトする方法を示します。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using GrapeCity.Win.CalendarGrid;

namespace CalendarGridSampleCode
{
    public class EditingDemo : Form
    {
        private GcCalendarGrid gcCalendarGrid = new GcCalendarGrid();
        
        public EditingDemo()
        {
            this.Text = "Editing Demo";
            this.Size = new Size(800, 700);
            this.StartPosition = FormStartPosition.CenterScreen;

            gcCalendarGrid.Template = this.CreateTemplate();

            gcCalendarGrid.CellContentButtonClick += gcCalendarGrid_CellContentButtonClick;
            gcCalendarGrid.CellEditingValueChanged += gcCalendarGrid_CellEditingValueChanged;
            gcCalendarGrid.CellBeginEdit += gcCalendarGrid_CellBeginEdit;
            gcCalendarGrid.CellEndEdit += gcCalendarGrid_CellEndEdit;
            gcCalendarGrid.CurrentCellPositionChanging += gcCalendarGrid_CurrentCellPositionChanging;

            this.Load += EditingDemo_Load;
            // Add GcCalendarGrid to form
            this.gcCalendarGrid.Dock = DockStyle.Fill;
            this.Controls.Add(this.gcCalendarGrid);
        }

        void gcCalendarGrid_CellEditingValueChanged(object sender, CalendarCellEditingValueChangedEventArgs e)
        {
            //This is a CheckBoxCell
            if (e.CellPosition.Scope == CalendarTableScope.Content && e.CellPosition.RowIndex == 2 && e.CellPosition.ColumnIndex == 1)
            {
                if (object.Equals(e.Value, true))
                {
                    this.gcCalendarGrid[e.CellPosition.Date][2, 0].Value = "True";
                    this.gcCalendarGrid[e.CellPosition.Date][2, 0].CellStyle.BackColor = Color.Lime;
                }
                else
                {
                    this.gcCalendarGrid[e.CellPosition.Date][2, 0].Value = "False";
                    this.gcCalendarGrid[e.CellPosition.Date][2, 0].CellStyle.BackColor = Color.Red;
                }
            }
        }

        void gcCalendarGrid_CellContentButtonClick(object sender, CalendarCellEventArgs e)
        {
            //This is a button cell
            if (e.CellPosition.Scope == CalendarTableScope.Content && e.CellPosition.RowIndex == 1 && e.CellPosition.ColumnIndex == 1)
            {
                CalendarCellPosition prevCell = new CalendarCellPosition(e.CellPosition.Date, 1, 0);
                this.gcCalendarGrid.BeginEdit(false);
            }
        }

        void gcCalendarGrid_CellBeginEdit(object sender, CalendarCellBeginEditEventArgs e)
        {
            if (GetMessageDeviceType() == MessageDeviceType.Touch 
                && (e.CellPosition.Scope == CalendarTableScope.Content && e.CellPosition.RowIndex == 1 && e.CellPosition.ColumnIndex == 0))
            {
                gcCalendarGrid.ShowTouchKeyboard();
            }
        }

        void gcCalendarGrid_CellEndEdit(object sender, CalendarCellEndEditEventArgs e)
        {
            gcCalendarGrid.HideTouchKeyboard();
        }

        void gcCalendarGrid_CurrentCellPositionChanging(object sender, CalendarCellPositionChangingEventArgs e)
        {
            if (e.NewCellPosition.Scope == CalendarTableScope.Content && e.NewCellPosition.RowIndex == 1 && e.NewCellPosition.ColumnIndex == 1)
            {
                e.NewCellPosition = new CalendarCellPosition(e.NewCellPosition.Date, 1, 0);
            }
        }

        void EditingDemo_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < this.gcCalendarGrid.LayoutSettings.HorizontalLayoutInfo.Count; i++)
            {
                this.gcCalendarGrid.LayoutSettings.PerformHorizontalAutoFit(i);
            }
        }

        private CalendarTemplate CreateTemplate()
        {
            GrapeCity.Win.CalendarGrid.CalendarTemplate calendarTemplate1 = new GrapeCity.Win.CalendarGrid.CalendarTemplate();
            GrapeCity.Win.CalendarGrid.CalendarHeaderCellType calendarHeaderCellType1 = new GrapeCity.Win.CalendarGrid.CalendarHeaderCellType();
            GrapeCity.Win.CalendarGrid.CalendarHeaderCellType calendarHeaderCellType2 = new GrapeCity.Win.CalendarGrid.CalendarHeaderCellType();
            GrapeCity.Win.CalendarGrid.CalendarButtonCellType calendarButtonCellType1 = new GrapeCity.Win.CalendarGrid.CalendarButtonCellType();
            GrapeCity.Win.CalendarGrid.CalendarCheckBoxCellType calendarCheckBoxCellType1 = new GrapeCity.Win.CalendarGrid.CalendarCheckBoxCellType();

            calendarTemplate1.ColumnCount = 2;
            calendarTemplate1.RowCount = 3;
            calendarTemplate1.RowHeaderColumnCount = 0;
            calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle";
            calendarHeaderCellType1.SupportLocalization = true;
            calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1;
            calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}";
            calendarTemplate1.ColumnHeader.GetCell(0, 0).RowSpan = 1;
            calendarTemplate1.ColumnHeader.GetCell(0, 0).ColumnSpan = 2;
            calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter;
            calendarHeaderCellType2.SupportLocalization = true;
            calendarTemplate1.ColumnHeader.GetCell(0, 1).CellType = calendarHeaderCellType2;
            calendarTemplate1.Content.CellStyleName = "defaultStyle";
            calendarTemplate1.Content.GetColumn(1).Width = 145;
            calendarTemplate1.Content.GetRow(1).Height = 28;
            calendarTemplate1.Content.GetRow(2).Height = 28;
            calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日";
            calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet;
            calendarTemplate1.Content.GetCell(0, 0).RowSpan = 1;
            calendarTemplate1.Content.GetCell(0, 0).ColumnSpan = 2;
            calendarButtonCellType1.SupportLocalization = true;
            calendarTemplate1.Content.GetCell(1, 1).CellType = calendarButtonCellType1;
            calendarTemplate1.Content.GetCell(1, 1).Value = "Click/Tap To Edit Cell";
            calendarTemplate1.Content.GetCell(1, 1).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter;
            calendarCheckBoxCellType1.SupportLocalization = true;
            calendarTemplate1.Content.GetCell(2, 1).CellType = calendarCheckBoxCellType1;

            return calendarTemplate1;
        }
        // Mouse event is from touch or not.
        [DllImport("user32.dll")]
        private static extern uint GetMessageExtraInfo();

        private static MessageDeviceType GetMessageDeviceType()
        {
            uint extra = GetMessageExtraInfo();
            if ((extra & 0xFF515780) == 0xFF515780)
            {
                return MessageDeviceType.Touch;
            }
            else if ((extra & 0xFF515700) == 0xFF515700)
            {
                return MessageDeviceType.Pen;
            }
            else
            {
                return MessageDeviceType.Mouse;
            }
        }

        internal enum MessageDeviceType
        {
            Mouse,
            Touch,
            Pen
        }

        [STAThreadAttribute()]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new EditingDemo());
        }
    }
}
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Windows.Forms
Imports GrapeCity.Win.CalendarGrid

Namespace CalendarGridSampleCode
    Public Class EditingDemo
        Inherits Form
        Private gcCalendarGrid As New GcCalendarGrid()

        Public Sub New()
            Me.Text = "Editing Demo"
            Me.Size = New Size(800, 700)
            Me.StartPosition = FormStartPosition.CenterScreen

            gcCalendarGrid.Template = Me.CreateTemplate()

            AddHandler gcCalendarGrid.CellContentButtonClick, AddressOf gcCalendarGrid_CellContentButtonClick
            AddHandler gcCalendarGrid.CellEditingValueChanged, AddressOf gcCalendarGrid_CellEditingValueChanged
            AddHandler gcCalendarGrid.CellBeginEdit, AddressOf gcCalendarGrid_CellBeginEdit
            AddHandler gcCalendarGrid.CellEndEdit, AddressOf gcCalendarGrid_CellEndEdit
            AddHandler gcCalendarGrid.CurrentCellPositionChanging, AddressOf gcCalendarGrid_CurrentCellPositionChanging

            AddHandler Me.Load, AddressOf EditingDemo_Load
            ' Add GcCalendarGrid to form
            Me.gcCalendarGrid.Dock = DockStyle.Fill
            Me.Controls.Add(Me.gcCalendarGrid)
        End Sub

        Private Sub gcCalendarGrid_CellEditingValueChanged(sender As Object, e As CalendarCellEditingValueChangedEventArgs)
            'This is a CheckBoxCell
            If e.CellPosition.Scope = CalendarTableScope.Content AndAlso e.CellPosition.RowIndex = 2 AndAlso e.CellPosition.ColumnIndex = 1 Then
                If Object.Equals(e.Value, True) Then
                    Me.gcCalendarGrid(e.CellPosition.[Date])(2, 0).Value = "True"
                    Me.gcCalendarGrid(e.CellPosition.[Date])(2, 0).CellStyle.BackColor = Color.Lime
                Else
                    Me.gcCalendarGrid(e.CellPosition.[Date])(2, 0).Value = "False"
                    Me.gcCalendarGrid(e.CellPosition.[Date])(2, 0).CellStyle.BackColor = Color.Red
                End If
            End If
        End Sub

        Private Sub gcCalendarGrid_CellContentButtonClick(sender As Object, e As CalendarCellEventArgs)
            'This is a button cell
            If e.CellPosition.Scope = CalendarTableScope.Content AndAlso e.CellPosition.RowIndex = 1 AndAlso e.CellPosition.ColumnIndex = 1 Then
                Dim prevCell As New CalendarCellPosition(e.CellPosition.[Date], 1, 0)
                Me.gcCalendarGrid.BeginEdit(False)
            End If
        End Sub

        Private Sub gcCalendarGrid_CellBeginEdit(sender As Object, e As CalendarCellBeginEditEventArgs)
            If GetMessageDeviceType() = MessageDeviceType.Touch AndAlso (e.CellPosition.Scope = CalendarTableScope.Content AndAlso e.CellPosition.RowIndex = 1 AndAlso e.CellPosition.ColumnIndex = 0) Then
                gcCalendarGrid.ShowTouchKeyboard()
            End If
        End Sub

        Private Sub gcCalendarGrid_CellEndEdit(sender As Object, e As CalendarCellEndEditEventArgs)
            gcCalendarGrid.HideTouchKeyboard()
        End Sub

        Private Sub gcCalendarGrid_CurrentCellPositionChanging(sender As Object, e As CalendarCellPositionChangingEventArgs)
            If e.NewCellPosition.Scope = CalendarTableScope.Content AndAlso e.NewCellPosition.RowIndex = 1 AndAlso e.NewCellPosition.ColumnIndex = 1 Then
                e.NewCellPosition = New CalendarCellPosition(e.NewCellPosition.[Date], 1, 0)
            End If
        End Sub

        Private Sub EditingDemo_Load(sender As Object, e As EventArgs)
            For i As Integer = 0 To Me.gcCalendarGrid.LayoutSettings.HorizontalLayoutInfo.Count - 1
                Me.gcCalendarGrid.LayoutSettings.PerformHorizontalAutoFit(i)
            Next
        End Sub

        Private Function CreateTemplate() As CalendarTemplate
            Dim calendarTemplate1 As New GrapeCity.Win.CalendarGrid.CalendarTemplate()
            Dim calendarHeaderCellType1 As New GrapeCity.Win.CalendarGrid.CalendarHeaderCellType()
            Dim calendarHeaderCellType2 As New GrapeCity.Win.CalendarGrid.CalendarHeaderCellType()
            Dim calendarButtonCellType1 As New GrapeCity.Win.CalendarGrid.CalendarButtonCellType()
            Dim calendarCheckBoxCellType1 As New GrapeCity.Win.CalendarGrid.CalendarCheckBoxCellType()

            calendarTemplate1.ColumnCount = 2
            calendarTemplate1.RowCount = 3
            calendarTemplate1.RowHeaderColumnCount = 0
            calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle"
            calendarHeaderCellType1.SupportLocalization = True
            calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1
            calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}"
            calendarTemplate1.ColumnHeader.GetCell(0, 0).RowSpan = 1
            calendarTemplate1.ColumnHeader.GetCell(0, 0).ColumnSpan = 2
            calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter
            calendarHeaderCellType2.SupportLocalization = True
            calendarTemplate1.ColumnHeader.GetCell(0, 1).CellType = calendarHeaderCellType2
            calendarTemplate1.Content.CellStyleName = "defaultStyle"
            calendarTemplate1.Content.GetColumn(1).Width = 145
            calendarTemplate1.Content.GetRow(1).Height = 28
            calendarTemplate1.Content.GetRow(2).Height = 28
            calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日"
            calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet
            calendarTemplate1.Content.GetCell(0, 0).RowSpan = 1
            calendarTemplate1.Content.GetCell(0, 0).ColumnSpan = 2
            calendarButtonCellType1.SupportLocalization = True
            calendarTemplate1.Content.GetCell(1, 1).CellType = calendarButtonCellType1
            calendarTemplate1.Content.GetCell(1, 1).Value = "Click/Tap To Edit Cell"
            calendarTemplate1.Content.GetCell(1, 1).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter
            calendarCheckBoxCellType1.SupportLocalization = True
            calendarTemplate1.Content.GetCell(2, 1).CellType = calendarCheckBoxCellType1

            Return calendarTemplate1
        End Function
        ' Mouse event is from touch or not.
        <DllImport("user32.dll")> _
        Private Shared Function GetMessageExtraInfo() As UInteger
        End Function

        Private Shared Function GetMessageDeviceType() As MessageDeviceType
            Dim extra As UInteger = GetMessageExtraInfo()
            If (extra And &HFF515780UI) = &HFF515780UI Then
                Return MessageDeviceType.Touch
            ElseIf (extra And &HFF515700UI) = &HFF515700UI Then
                Return MessageDeviceType.Pen
            Else
                Return MessageDeviceType.Mouse
            End If
        End Function

        Friend Enum MessageDeviceType
            Mouse
            Touch
            Pen
        End Enum

        <STAThreadAttribute> _
        Public Shared Sub Main()
            Application.EnableVisualStyles()
            Application.Run(New EditingDemo())
        End Sub
    End Class
End Namespace
参照

GcCalendarGrid クラス
GcCalendarGrid メンバ

 

 


c 2008 GrapeCity inc. All rights reserved.