PowerTools CalendarGrid for Windows Forms 1.0J
SelectionMode プロパティ
使用例 

GcCalendarGrid コントロールの選択モードを取得または設定します。
構文
Public Property SelectionMode As CalendarGridSelectionMode
public CalendarGridSelectionMode SelectionMode {get; set;}

プロパティ値

CalendarGridSelectionMode 値の 1 つ。既定値は CalendarGridSelectionMode.Multiple です。
解説
値が CalendarGridSelectionMode.Single の場合、[Ctrl]+ マウスクリックまたは[Shift]+ 方向キーを使用して複数のセルまたは日付を選択することはできません。1 つのセルまたは日付のみを選択できます。
使用例
次のサンプルコードは、GcCalendarGrid の選択プロパティの使用方法を示します。
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using GrapeCity.Win.CalendarGrid;

namespace CalendarGridSampleCode
{
    public class SelectionDemo : Form
    {
        private GcCalendarGrid gcCalendarGrid = new GcCalendarGrid();
        private FlowLayoutPanel panel = new FlowLayoutPanel();

        public SelectionDemo()
        {
            this.Text = "Selection Demo";
            this.Size = new Size(950, 600);

            // Initial flow layout panel and add to form.
            this.panel.Dock = DockStyle.Right;
            this.panel.FlowDirection = FlowDirection.TopDown;
            this.panel.WrapContents = false;
            this.panel.Padding = new Padding(5);
            this.Controls.Add(panel);

            // Add GcCalendarGrid to form
            this.gcCalendarGrid.Dock = DockStyle.Left;
            gcCalendarGrid.Width = 740;
            this.Controls.Add(this.gcCalendarGrid);

            this.Load += Form1_Load;

            InitControls();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gcCalendarGrid.SelectionChanged += gcCalendarGrid_SelectionChanged;
        }

        #region Event Handlers

        void allowMultiSelectCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // Only can select one cell or row, when MultiSelect property is false.
            this.gcCalendarGrid.SelectionMode = allowMultiSelectCheckBox.Checked ? CalendarGridSelectionMode.Multiple : CalendarGridSelectionMode.Single;
        }

        void getSelectionInformationButton_Click(object sender, EventArgs e)
        {
            string info = null;

            info += "Selected cells List:";

            // Get all selected cell list.
            foreach (CalendarCellPosition cell in this.gcCalendarGrid.SelectedCells)
            {
                info += "\r\n";

                info += "Date: " + cell.Date + ",RowIndex: " + cell.RowIndex + ", ColumnIndex: " + cell.ColumnIndex;
            }

            info += "\r\n\r\n";

            info += ("Selected Dates List:");

            // Get all selected row list.
            foreach (DateTime date in this.gcCalendarGrid.SelectedDates)
            {
                info += "\r\n";

                info += "DateTime: " + date;
            }

            MessageBox.Show(info);
        }

        void gcCalendarGrid_SelectionChanged(object sender, EventArgs e)
        {
            this.Text = "Selected cell count: " + this.gcCalendarGrid.SelectedCells.Count;
            this.Text += "  Selected dates count: " + this.gcCalendarGrid.SelectedDates.Count;
        }

        void selectionUnitComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.gcCalendarGrid.SelectionUnit = (SelectionUnit)selectionUnitComboBox.SelectedItem;
        }

        #endregion

        #region Initialize Buttons

        private void InitControls()
        {
            allowMultiSelectCheckBox.CheckState = CheckState.Checked;
            allowMultiSelectCheckBox.CheckedChanged += allowMultiSelectCheckBox_CheckedChanged;

            selectionUnitComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            selectionUnitComboBox.SelectedIndexChanged += selectionUnitComboBox_SelectedIndexChanged;
            selectionUnitComboBox.Items.AddRange(new object[] { SelectionUnit.Cell, SelectionUnit.Date });
            selectionUnitComboBox.SelectedValue = SelectionUnit.Cell;

            getSelectionInformationButton.Click += getSelectionInformationButton_Click;

            AddControl(allowMultiSelectCheckBox, "Allow multi-select");
            AddControl(selectionUnitComboBox, "cell");
            AddControl(getSelectionInformationButton, "Show selection information");
        }

        private void AddControl(Control control, string text)
        {
            this.panel.Controls.Add(control);
            control.Text = text;
            control.AutoSize = true;
        }

        CheckBox allowMultiSelectCheckBox = new CheckBox();
        ComboBox selectionUnitComboBox = new ComboBox();
        Button getSelectionInformationButton = new Button();

        #endregion

        [STAThreadAttribute()]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new SelectionDemo());
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Text
Imports GrapeCity.Win.CalendarGrid

Namespace CalendarGridSampleCode
    Public Class SelectionDemo
        Inherits Form
        Private gcCalendarGrid As New GcCalendarGrid()
        Private panel As New FlowLayoutPanel()

        Public Sub New()
            Me.Text = "Selection Demo"
            Me.Size = New Size(950, 600)

            ' Initial flow layout panel and add to form.
            Me.panel.Dock = DockStyle.Right
            Me.panel.FlowDirection = FlowDirection.TopDown
            Me.panel.WrapContents = False
            Me.panel.Padding = New Padding(5)
            Me.Controls.Add(panel)

            ' Add GcCalendarGrid to form
            Me.gcCalendarGrid.Dock = DockStyle.Left
            gcCalendarGrid.Width = 740
            Me.Controls.Add(Me.gcCalendarGrid)

            AddHandler Me.Load, AddressOf Form1_Load

            InitControls()
        End Sub

        Private Sub Form1_Load(sender As Object, e As EventArgs)
            AddHandler gcCalendarGrid.SelectionChanged, AddressOf gcCalendarGrid_SelectionChanged
        End Sub

#Region "Event Handlers"

        Private Sub allowMultiSelectCheckBox_CheckedChanged(sender As Object, e As EventArgs)
            ' Only can select one cell or row, when MultiSelect property is false.
            Me.gcCalendarGrid.SelectionMode = If(allowMultiSelectCheckBox.Checked, CalendarGridSelectionMode.Multiple, CalendarGridSelectionMode.[Single])
        End Sub

        Private Sub getSelectionInformationButton_Click(sender As Object, e As EventArgs)
            Dim info As String = Nothing

            info += "Selected cells List:"

            ' Get all selected cell list.
            For Each cell As CalendarCellPosition In Me.gcCalendarGrid.SelectedCells
                info += vbCr & vbLf

                info += "Date: " + cell.[Date] + ",RowIndex: " + cell.RowIndex + ", ColumnIndex: " + cell.ColumnIndex
            Next

            info += vbCr & vbLf & vbCr & vbLf

            info += ("Selected Dates List:")

            ' Get all selected row list.
            For Each [date] As DateTime In Me.gcCalendarGrid.SelectedDates
                info += vbCr & vbLf

                info += "DateTime: " + [date]
            Next

            MessageBox.Show(info)
        End Sub

        Private Sub gcCalendarGrid_SelectionChanged(sender As Object, e As EventArgs)
            Me.Text = "Selected cell count: " + Me.gcCalendarGrid.SelectedCells.Count
            Me.Text += "  Selected dates count: " + Me.gcCalendarGrid.SelectedDates.Count
        End Sub

        Private Sub selectionUnitComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
            Me.gcCalendarGrid.SelectionUnit = DirectCast(selectionUnitComboBox.SelectedItem, SelectionUnit)
        End Sub

#End Region

#Region "Initialize Buttons"

        Private Sub InitControls()
            allowMultiSelectCheckBox.CheckState = CheckState.Checked
            AddHandler allowMultiSelectCheckBox.CheckedChanged, AddressOf allowMultiSelectCheckBox_CheckedChanged

            selectionUnitComboBox.DropDownStyle = ComboBoxStyle.DropDownList
            AddHandler selectionUnitComboBox.SelectedIndexChanged, AddressOf selectionUnitComboBox_SelectedIndexChanged
            selectionUnitComboBox.Items.AddRange(New Object() {SelectionUnit.Cell, SelectionUnit.[Date]})
            selectionUnitComboBox.SelectedValue = SelectionUnit.Cell

            AddHandler getSelectionInformationButton.Click, AddressOf getSelectionInformationButton_Click

            AddControl(allowMultiSelectCheckBox, "Allow multi-select")
            AddControl(selectionUnitComboBox, "cell")
            AddControl(getSelectionInformationButton, "Show selection information")
        End Sub

        Private Sub AddControl(control As Control, text As String)
            Me.panel.Controls.Add(control)
            control.Text = text
            control.AutoSize = True
        End Sub

        Private allowMultiSelectCheckBox As New CheckBox()
        Private selectionUnitComboBox As New ComboBox()
        Private getSelectionInformationButton As New Button()

#End Region

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

GcCalendarGrid クラス
GcCalendarGrid メンバ

 

 


© 2014 GrapeCity inc. All rights reserved.