PowerTools MultiRow for Windows Forms 8.0J
ViewMode プロパティ
使用例 

GcMultiRowの表示モードを示す値を取得または設定します。
構文
Public Property ViewMode As ViewMode
public ViewMode ViewMode {get; set;}

プロパティ値

GcMultiRowの表示モードを示すViewMode値の1つ。既定値はViewMode.Defaultです。
例外
例外解説
System.ComponentModel.InvalidEnumArgumentException指定された値がViewMode値の1つではありません。
解説
GcMultiRowコントロールには複数の表示モードがあります。ViewMode.Defaultモードでは、GcMultiRowのCellを選択して編集できます。ViewMode.DisplayモードではGcMultiRowの表示のみが可能で、選択や編集はできません。ViewMode.Rowモードでは、一度に1つのRowを選択できます。ViewMode.ListBoxモードでは、System.Windows.Forms.ListBoxコントロールのようにGcMultiRowを選択できます。
使用例
次のサンプルコードは、MultiRowコントロールの選択動作をカスタマイズする方法を示します。MultiRowコントロールでは、複数要素と単一要素のどちらを選択できるようにするか、セルをクリックして選択状態を切り替えられるようにするかどうか、などを指定できます。
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Text;

namespace GrapeCity.Win.MultiRow.SampleCode
{
    public class SelectionDemo : Form
    {
        private GcMultiRow gcMultiRow1 = new GcMultiRow();
        private FlowLayoutPanel panel = new FlowLayoutPanel();

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

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

            // Add MultiRow to form
            this.gcMultiRow1.Dock = DockStyle.Left;
            this.gcMultiRow1.Width = 320;
            this.Controls.Add(this.gcMultiRow1);

            this.Load += new EventHandler(Form1_Load);

            InitControls();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gcMultiRow1.Template = Template.CreateGridTemplate(3);

            gcMultiRow1.RowCount = 10;

            gcMultiRow1.SelectionChanged += new EventHandler(gcMultiRow1_SelectionChanged);
        }

        #region Event Handlers

        void allowMultiSelectCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // Only can select one cell or row, when MultiSelect property is false.
            this.gcMultiRow1.MultiSelect = allowMultiSelectCheckBox.Checked;
        }

        void allowReverseSelectCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // When allow reverse select, user can reverse select a cell by mouse click with Ctrl key pressed. 
            this.gcMultiRow1.AllowUserToReverseSelect = allowReverseSelectCheckBox.Checked;
        }

        void allowShiftSelectCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // When allow shift select, user can select a range by pressing shift key and pressing navigation key or clicking mouse left button.
            this.gcMultiRow1.AllowUserToShiftSelect = allowShiftSelectCheckBox.Checked;
        }

        void switchViewModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (switchViewModeComboBox.Text == "Can select cell and row")
            {
                // In default mode, user can select rows and cells.
                this.gcMultiRow1.ViewMode = ViewMode.Default;
            }
            else if (switchViewModeComboBox.Text == "Only can select row")
            {
                // In row mode, user only can select rows.
                this.gcMultiRow1.ViewMode = ViewMode.Row;
            }
            else if (switchViewModeComboBox.Text == "List box like selection")
            {
                // In list box mode, user only can select rows. And selection policy is most like list box control.
                this.gcMultiRow1.ViewMode = ViewMode.ListBox;
            }
            else if (switchViewModeComboBox.Text == "Disable selection")
            {
                // Disable all select ability.
                this.gcMultiRow1.ViewMode = ViewMode.Display;
            }

            // When view mode is ListBox, MultiSelect property and AllowUserReverseSelect property do not take effect.
            allowMultiSelectCheckBox.Enabled = (this.gcMultiRow1.ViewMode != ViewMode.ListBox);
            allowReverseSelectCheckBox.Enabled = (this.gcMultiRow1.ViewMode != ViewMode.ListBox);
        }

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

            // Get a specific cell's selection state.
            info = "First Cell's Selection State: " + gcMultiRow1[0, 0].Selected;

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

            // Get a specific row's selection state.
            info += "First Row's Selection State: " + gcMultiRow1.Rows[0].Selected;

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

            info += "Selected cells List:";

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

                info += "RowIndex: " + cell.RowIndex + ", CellIndex: " + cell.CellIndex;
            }

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

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

            // Get all selected row list.
            foreach (Row row in this.gcMultiRow1.SelectedRows)
            {
                info += "\r\n";

                info += "RowIndex: " + row.Index;
            }

            MessageBox.Show(info);
        }

        void gcMultiRow1_SelectionChanged(object sender, EventArgs e)
        {
            this.Text = "Selected cell count: " + this.gcMultiRow1.SelectedCells.Count;
            this.Text += "  Selected row count: " + this.gcMultiRow1.SelectedRows.Count;
        }

        #endregion

        #region Initialize Buttons

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

            allowReverseSelectCheckBox.CheckedChanged += new EventHandler(allowReverseSelectCheckBox_CheckedChanged);
            allowShiftSelectCheckBox.CheckedChanged += new EventHandler(allowShiftSelectCheckBox_CheckedChanged);

            switchViewModeComboBox.Items.Add("Can select cell and row");
            switchViewModeComboBox.Items.Add("Only can select row");
            switchViewModeComboBox.Items.Add("List box like selection");
            switchViewModeComboBox.Items.Add("Disable selection");
            switchViewModeComboBox.Width = 150;
            switchViewModeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            switchViewModeComboBox.SelectedIndexChanged += new EventHandler(switchViewModeComboBox_SelectedIndexChanged);

            getSelectionInformationButton.Click += new EventHandler(getSelectionInformationButton_Click);

            AddControl(allowMultiSelectCheckBox, "Allow multi-select");
            AddControl(allowReverseSelectCheckBox, "Allow reverse select when press Ctrl");
            AddControl(allowShiftSelectCheckBox, "Allow select a range when press Shift");
            AddControl(switchViewModeComboBox, "Can select cell and row");
            AddControl(getSelectionInformationButton, "Show selection information");
        }

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

        CheckBox allowMultiSelectCheckBox = new CheckBox();
        CheckBox allowReverseSelectCheckBox = new CheckBox();
        CheckBox allowShiftSelectCheckBox = new CheckBox();
        ComboBox switchViewModeComboBox = new ComboBox();
        Button getSelectionInformationButton = new Button();

        #endregion

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

Public Class SelectionDemo
    Inherits Form
    Friend WithEvents gcMultiRow1 As New GcMultiRow()
    Private panel As New FlowLayoutPanel()

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

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

        ' Add MultiRow to form
        Me.gcMultiRow1.Dock = DockStyle.Left
        Me.gcMultiRow1.Width = 320
        Me.Controls.Add(Me.gcMultiRow1)

        InitControls()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        gcMultiRow1.Template = Template.CreateGridTemplate(3)

        gcMultiRow1.RowCount = 10
    End Sub

#Region "Event Handlers"

    Private Sub allowMultiSelectCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles allowMultiSelectCheckBox.CheckedChanged
        ' Only can select one cell or row, when MultiSelect property is false.
        Me.gcMultiRow1.MultiSelect = allowMultiSelectCheckBox.Checked
    End Sub

    Private Sub allowReverseSelectCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles allowReverseSelectCheckBox.CheckedChanged
        ' When allow reverse select, user can reverse select a cell by mouse click with Ctrl key pressed. 
        Me.gcMultiRow1.AllowUserToReverseSelect = allowReverseSelectCheckBox.Checked
    End Sub

    Private Sub allowShiftSelectCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles allowShiftSelectCheckBox.CheckedChanged
        ' When allow shift select, user can select a range by pressing shift key and pressing navigation key or clicking mouse left button.
        Me.gcMultiRow1.AllowUserToShiftSelect = allowShiftSelectCheckBox.Checked
    End Sub

    Private Sub switchViewModeComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles switchViewModeComboBox.SelectedIndexChanged
        If switchViewModeComboBox.Text = "Can select cell and row" Then
            ' In default mode, user can select rows and cells.
            Me.gcMultiRow1.ViewMode = ViewMode.Default
        ElseIf switchViewModeComboBox.Text = "Only can select row" Then
            ' In row mode, user only can select rows.
            Me.gcMultiRow1.ViewMode = ViewMode.Row
        ElseIf switchViewModeComboBox.Text = "List box like selection" Then
            ' In list box mode, user only can select rows. And selection policy is most like list box control.
            Me.gcMultiRow1.ViewMode = ViewMode.ListBox
        ElseIf switchViewModeComboBox.Text = "Disable selection" Then
            ' Disable all select ability.
            Me.gcMultiRow1.ViewMode = ViewMode.Display
        End If

        ' When view mode is ListBox, MultiSelect property and AllowUserReverseSelect property do not take effect.
        allowMultiSelectCheckBox.Enabled = (Me.gcMultiRow1.ViewMode <> ViewMode.ListBox)
        allowReverseSelectCheckBox.Enabled = (Me.gcMultiRow1.ViewMode <> ViewMode.ListBox)
    End Sub

    Private Sub getSelectionInformationButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles getSelectionInformationButton.Click
        Dim info As String = Nothing

        ' Get a specific cell's selection state.
        info = "First Cell's Selection State: " + gcMultiRow1(0, 0).Selected.ToString()

        info += vbCr & vbLf & vbCr & vbLf

        ' Get a specific row's selection state.
        info += "First Row's Selection State: " + gcMultiRow1.Rows(0).Selected.ToString()

        info += vbCr & vbLf & vbCr & vbLf

        info += "Selected cells List:"

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

            info += "RowIndex: " + cell.RowIndex.ToString() + ", CellIndex: " + cell.CellIndex.ToString()
        Next

        info += vbCr & vbLf & vbCr & vbLf

        info += ("Selected rows List:")

        ' Get all selected row list.
        For Each row As Row In Me.gcMultiRow1.SelectedRows
            info += vbCr & vbLf

            info += "RowIndex: " + row.Index.ToString()
        Next

        MessageBox.Show(info)
    End Sub

    Private Sub gcMultiRow1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gcMultiRow1.SelectionChanged
        Me.Text = "Selected cell count: " + Me.gcMultiRow1.SelectedCells.Count.ToString()
        Me.Text += "  Selected row count: " + Me.gcMultiRow1.SelectedRows.Count.ToString()
    End Sub

#End Region

#Region "Initialize Buttons"

    Private Sub InitControls()
        allowMultiSelectCheckBox.CheckState = CheckState.Checked

        switchViewModeComboBox.Items.Add("Can select cell and row")
        switchViewModeComboBox.Items.Add("Only can select row")
        switchViewModeComboBox.Items.Add("List box like selection")
        switchViewModeComboBox.Items.Add("Disable selection")
        switchViewModeComboBox.Width = 150
        switchViewModeComboBox.DropDownStyle = ComboBoxStyle.DropDownList

        AddControl(allowMultiSelectCheckBox, "Allow multi-select")
        AddControl(allowReverseSelectCheckBox, "Allow reverse select when press Ctrl")
        AddControl(allowShiftSelectCheckBox, "Allow select a range when press Shift")
        AddControl(switchViewModeComboBox, "Can select cell and row")
        AddControl(getSelectionInformationButton, "Show selection information")
    End Sub

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

    Friend WithEvents allowMultiSelectCheckBox As New CheckBox()
    Friend WithEvents allowReverseSelectCheckBox As New CheckBox()
    Friend WithEvents allowShiftSelectCheckBox As New CheckBox()
    Friend WithEvents switchViewModeComboBox As New ComboBox()
    Friend WithEvents getSelectionInformationButton As New Button()

#End Region

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

GcMultiRow クラス
GcMultiRow メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.