DataGridView.MultiSelect プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim value As Boolean value = instance.MultiSelect instance.MultiSelect = value
/** @property */ public boolean get_MultiSelect () /** @property */ public void set_MultiSelect (boolean value)
ユーザーが複数のセル、行、または列を同時に選択できる場合は true。それ以外の場合は false。既定値は true です。

MultiSelect プロパティが true に設定されている場合、DataGridView コントロールで複数の要素 (セル、行、または列) を選択できます。複数の要素を選択するには、ユーザーは Ctrl キーを押したまま選択する要素をクリックします。選択する最初の要素をクリックしてから、Shift キーを押したまま選択する最後の要素をクリックすると、連続する要素を選択できます。選択範囲は SelectionMode プロパティに基づいています。たとえば、SelectionMode が DataGridViewSelectionMode.FullColumnSelect に設定されている場合、ユーザーは複数の列を選択できます。
MultiSelect プロパティを使用すると、ユーザーは DataGridView コントロールで複数の要素を選択して、選択されたすべての要素で同じ操作を実行できます。たとえば、ユーザーは複数のセルを選択してから、選択したセルを右クリックすると、それらのセルに対して実行されるタスクのセットを表示するショートカット メニューを表示できます。
DataGridView コントロールで選択されているセル、行、または列を確認するには、SelectedCells プロパティ、SelectedRows プロパティ、または SelectedColumns プロパティにアクセスします。選択されているセルの数を確認するには、DataGridViewElementStates.Selected の引数値を指定して、GetCellCount メソッドを呼び出します。選択された行数を取得するには GetRowCount メソッド、列数を取得するには GetColumnCount メソッドを使用します。大量のデータを処理する場合、コレクションに直接アクセスするよりも、これらのメソッドを使用する方が効率的です。詳細については、「Windows フォーム DataGridView コントロールを拡張するための推奨される手順」を参照してください。

MultiSelect プロパティを使用する方法を次のコード例に示します。この例を実行するには、dataGridView1 という名前の DataGridView が配置されているフォームにコードを貼り付け、フォームのコンストラクタまたは Load イベント ハンドラから SetUpDataGridView メソッドを呼び出します。必ずすべてのイベントをイベント ハンドラに関連付けるようにしてください。
Private Sub SetUpDataGridView() Me.Controls.Add(dataGridView1) dataGridView1.ColumnCount = 5 With dataGridView1.ColumnHeadersDefaultCellStyle .BackColor = Color.Navy .ForeColor = Color.White .Font = New Font(dataGridView1.Font, FontStyle.Bold) End With With dataGridView1 .EditMode = DataGridViewEditMode.EditOnEnter .Name = "dataGridView1" .Location = New Point(8, 8) .Size = New Size(500, 300) .AutoSizeRowsMode = _ DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders .ColumnHeadersBorderStyle = _ DataGridViewHeaderBorderStyle.Raised .CellBorderStyle = _ DataGridViewCellBorderStyle.Single .GridColor = SystemColors.ActiveBorder .RowHeadersVisible = False .Columns(0).Name = "Release Date" .Columns(1).Name = "Track" .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns(2).Name = "Title" .Columns(3).Name = "Artist" .Columns(4).Name = "Album" ' Make the font italic for row four. .Columns(4).DefaultCellStyle.Font = _ New Font(Control.DefaultFont, _ FontStyle.Italic) .SelectionMode = _ DataGridViewSelectionMode.FullRowSelect .MultiSelect = False .BackgroundColor = Color.Honeydew .Dock = DockStyle.Fill End With End Sub
private void SetUpDataGridView() { this.Controls.Add(dataGridView1); dataGridView1.ColumnCount = 5; DataGridViewCellStyle style = dataGridView1.ColumnHeadersDefaultCellStyle; style.BackColor = Color.Navy; style.ForeColor = Color.White; style.Font = new Font(dataGridView1.Font, FontStyle.Bold); dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter; dataGridView1.Name = "dataGridView1"; dataGridView1.Location = new Point(8, 8); dataGridView1.Size = new Size(500, 300); dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised; dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; dataGridView1.GridColor = SystemColors.ActiveBorder; dataGridView1.RowHeadersVisible = false; dataGridView1.Columns[0].Name = "Release Date"; dataGridView1.Columns[1].Name = "Track"; dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.Columns[2].Name = "Title"; dataGridView1.Columns[3].Name = "Artist"; dataGridView1.Columns[4].Name = "Album"; // Make the font italic for row four. dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic); dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.MultiSelect = false; dataGridView1.BackgroundColor = Color.Honeydew; dataGridView1.Dock = DockStyle.Fill; dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting); dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing); addNewRowButton.Click += new EventHandler(addNewRowButton_Click); deleteRowButton.Click += new EventHandler(deleteRowButton_Click); ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click); dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating); }
void SetUpDataGridView() { this->Controls->Add( dataGridView1 ); dataGridView1->ColumnCount = 5; DataGridViewCellStyle^ style = dataGridView1->ColumnHeadersDefaultCellStyle; style->BackColor = Color::Navy; style->ForeColor = Color::White; style->Font = gcnew System::Drawing::Font( dataGridView1->Font,FontStyle::Bold ); dataGridView1->EditMode = DataGridViewEditMode::EditOnEnter; dataGridView1->Name = "dataGridView1"; dataGridView1->Location = Point(8,8); dataGridView1->Size = System::Drawing::Size( 500, 300 ); dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::DisplayedCellsExceptHeaders; dataGridView1->ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle::Raised; dataGridView1->CellBorderStyle = DataGridViewCellBorderStyle::Single; dataGridView1->GridColor = SystemColors::ActiveBorder; dataGridView1->RowHeadersVisible = false; dataGridView1->Columns[ 0 ]->Name = "Release Date"; dataGridView1->Columns[ 1 ]->Name = "Track"; dataGridView1->Columns[ 1 ]->DefaultCellStyle->Alignment = DataGridViewContentAlignment::MiddleCenter; dataGridView1->Columns[ 2 ]->Name = "Title"; dataGridView1->Columns[ 3 ]->Name = "Artist"; dataGridView1->Columns[ 4 ]->Name = "Album"; // Make the font italic for row four. dataGridView1->Columns[ 4 ]->DefaultCellStyle->Font = gcnew System::Drawing::Font( DataGridView::DefaultFont,FontStyle::Italic ); dataGridView1->SelectionMode = DataGridViewSelectionMode::FullRowSelect; dataGridView1->MultiSelect = false; dataGridView1->BackgroundColor = Color::Honeydew; dataGridView1->Dock = DockStyle::Fill; dataGridView1->CellFormatting += gcnew DataGridViewCellFormattingEventHandler( this, &Form1::dataGridView1_CellFormatting ); dataGridView1->CellParsing += gcnew DataGridViewCellParsingEventHandler( this, &Form1::dataGridView1_CellParsing ); addNewRowButton->Click += gcnew EventHandler( this, &Form1::addNewRowButton_Click ); deleteRowButton->Click += gcnew EventHandler( this, &Form1::deleteRowButton_Click ); ledgerStyleButton->Click += gcnew EventHandler( this, &Form1::ledgerStyleButton_Click ); dataGridView1->CellValidating += gcnew DataGridViewCellValidatingEventHandler( this, &Form1::dataGridView1_CellValidating ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
その他の技術情報
DataGridView コントロール (Windows フォーム)
- DataGridView.MultiSelect プロパティのページへのリンク