DataGridViewComboBoxColumnとは? わかりやすく解説

DataGridViewComboBoxColumn イベント


パブリック イベントパブリック イベント

  名前 説明
パブリック イベント Disposed  DataGridViewColumn が破棄されたときに発生します。 ( DataGridViewColumn から継承されます。)
参照参照

関連項目

DataGridViewComboBoxColumn クラス
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.DataSource プロパティ
DataGridViewColumn.DataPropertyName プロパティ
DataGridViewComboBoxColumn.DataSource プロパティ
DataGridViewComboBoxColumn.Items プロパティ
DataGridViewComboBoxColumn.ValueMember プロパティ
DataGridViewComboBoxColumn.DisplayMember プロパティ
DataGridViewColumn クラス
DataGridViewRow
DataGridViewComboBoxCell クラス
DataGridViewComboBoxEditingControl
DataGridViewColumn.SortMode プロパティ

DataGridViewComboBoxColumn クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

DataGridViewComboBoxCell オブジェクトの列を表します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class DataGridViewComboBoxColumn
    Inherits DataGridViewColumn
Dim instance As DataGridViewComboBoxColumn
public class DataGridViewComboBoxColumn : DataGridViewColumn
public ref class DataGridViewComboBoxColumn
 : public DataGridViewColumn
public class DataGridViewComboBoxColumn extends
 DataGridViewColumn
public class DataGridViewComboBoxColumn extends
 DataGridViewColumn
解説解説

DataGridViewComboBoxColumn クラスは、DataGridViewColumn の特殊な型で、選択および編集を行うためのセルを論理的にホストするために使用されます。DataGridViewComboBoxColumn には、それと交差するすべての DataGridViewRow 内に、関連付けられた DataGridViewComboBoxCell があります。

このクラスの一般的な使用方法は次のとおりです。

  1. DataGridView を作成します。

  2. DataGridView の DataSource プロパティを設定します。

  3. DataGridViewComboBoxColumn を作成します。

  4. データ ソースに複数のプロパティまたは列が含まれている場合は、DataPropertyName プロパティにセル値を決定するプロパティまたは列の名前を設定します。

  5. DataSource プロパティまたは Items プロパティを使用して選択項目を決定します。

  6. ValueMember プロパティと DisplayMember プロパティを使用して、セル値と画面に表示する項目との間にマップを確立します。

DataGridViewComboBoxColumn は、DataGridView.DataSource プロパティによって決定されるすべてのセル値と、DataSource プロパティまたは Items プロパティによって決定される一連の選択肢との間にマップが存在する場合のみ、正常に機能します。このマップが存在しない場合は、列が表示されたときに "書式設定と表示でエラーが発生しました" というメッセージが表示されます。

この列型の既定の並べ替えモードは、NotSortable です。

継承時の注意 DataGridViewComboBoxColumn からクラスを派生させて新しいプロパティを追加する場合は、Clone メソッドをオーバーライドして、クローン操作時に新しいプロパティをコピーする必要があります。また、基本クラスの Clone メソッドも呼び出して、基本クラスのプロパティが新しいセルにコピーされるようにする必要があります。

使用例使用例

DataGridViewComboBoxColumn を使用して、TitleOfCourtesy 列へのデータ入力を円滑化するコード例を次に示します。

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.Drawing

Public Class Employees
    Inherits System.Windows.Forms.Form

    Private WithEvents DataGridView1 As
 New DataGridView
    Private WithEvents DataGridView2 As
 New DataGridView

    <STAThreadAttribute()> _
    Public Shared Sub Main()
        Try
            Application.EnableVisualStyles()
            Application.Run(New Employees())
        Catch e As Exception
            MessageBox.Show(e.Message & e.StackTrace)
        End Try
    End Sub

    Private Sub Form1_Load(ByVal
 sender As System.Object, _
        ByVal e As System.EventArgs) Handles
 MyBase.Load

        Try
            SetUpForm()
            SetUpDataGridView1()
            SetUpDataGridView2()
        Catch ex As SqlException
            MessageBox.Show("The connection string <"
 _
                & connectionString _
                & "> failed to connect.  Modify it to connect
 to " _
                & "a Northwind database accessible to your
 system.", _
                "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Application.Exit()
        End Try
    End Sub

    Private Sub SetUpForm()
        Size = New Size(800, 600)
        Dim flowLayout As New
 FlowLayoutPanel()
        flowLayout.FlowDirection = FlowDirection.TopDown
        flowLayout.Dock = DockStyle.Fill
        Controls.Add(flowLayout)
        Text = "DataGridView columns demo"

        flowLayout.Controls.Add(DataGridView1)
        flowLayout.Controls.Add(DataGridView2)
    End Sub

    Private Sub SetUpDataGridView2()
        DataGridView2.Dock = DockStyle.Bottom
        DataGridView2.TopLeftHeaderCell.Value = "Sales Details"
        DataGridView2.RowHeadersWidthSizeMode = _
        DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
    End Sub

    Private Sub SetUpDataGridView1()
        ' Virtual mode is turned on so that the
        ' unbound DataGridViewCheckBoxColumn will
        ' keep its state when the bound columns are
        ' sorted.
        DataGridView1.VirtualMode = True

        DataGridView1.AutoSize = True
        DataGridView1.DataSource = _
            Populate("SELECT * FROM Employees")
        DataGridView1.TopLeftHeaderCell.Value = "Employees"
        DataGridView1.RowHeadersWidthSizeMode = _
            DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
        DataGridView1.ColumnHeadersHeightSizeMode = _
            DataGridViewColumnHeadersHeightSizeMode.AutoSize
        DataGridView1.AutoSizeColumnsMode = _
            DataGridViewAutoSizeColumnsMode.AllCells
        DataGridView1.AllowUserToAddRows = False
        DataGridView1.AllowUserToDeleteRows = False

        ' The below autogenerated column is removed so 
        ' a DataGridViewComboboxColumn could be used instead.
        DataGridView1.Columns.Remove( _
            ColumnName.TitleOfCourtesy.ToString())
        DataGridView1.Columns.Remove(ColumnName.ReportsTo.ToString())

        AddLinkColumn()
        AddComboBoxColumns()
        AddButtonColumn()
        AddOutOfOfficeColumn()
    End Sub

    ' Using an enum provides some abstraction between column index
    ' and column name along with compile time checking, and gives
    ' a handy place to store the column names.
    Enum ColumnName
        EmployeeId
        LastName
        FirstName
        Title
        TitleOfCourtesy
        BirthDate
        HireDate
        Address
        City
        Region
        PostalCode
        Country
        HomePhone
        Extension
        Photo
        Notes
        ReportsTo
        PhotoPath
        OutOfOffice
    End Enum

    Private Sub AddComboBoxColumns()
        Dim comboboxColumn As New
 DataGridViewComboBoxColumn()
        comboboxColumn = CreateComboBoxColumn()
        SetAlternateChoicesUsingDataSource(comboboxColumn)
        comboboxColumn.HeaderText = _
            "TitleOfCourtesy (via DataSource property)"
        DataGridView1.Columns.Insert(0, comboboxColumn)

        comboboxColumn = CreateComboBoxColumn()
        SetAlternateChoicesUsingItems(comboboxColumn)
        comboboxColumn.HeaderText = _
            "TitleOfCourtesy (via Items property)"
        ' Tack this example column onto the end.
        DataGridView1.Columns.Add(comboboxColumn)
    End Sub

    Private Sub AddLinkColumn()

        Dim links As New
 DataGridViewLinkColumn()
        With links
            .HeaderText = ColumnName.ReportsTo.ToString()
            .DataPropertyName = ColumnName.ReportsTo.ToString()
            .ActiveLinkColor = Color.White
            .LinkBehavior = LinkBehavior.SystemDefault
            .LinkColor = Color.Blue
            .TrackVisitedState = True
            .VisitedLinkColor = Color.YellowGreen
        End With
        DataGridView1.Columns.Add(links)
    End Sub

    Private Shared Sub SetAlternateChoicesUsingItems(
 _
        ByRef comboboxColumn As DataGridViewComboBoxColumn)

        With comboboxColumn
            .Items.AddRange(New String() _
                    {"Mr.", "Ms.",
 "Mrs.", "Dr."})
        End With
    End Sub

    Private Function CreateComboBoxColumn()
 _
        As DataGridViewComboBoxColumn
        Dim column As New
 DataGridViewComboBoxColumn()

        With column
            .DataPropertyName = ColumnName.TitleOfCourtesy.ToString()
            .HeaderText = ColumnName.TitleOfCourtesy.ToString()
            .DropDownWidth = 160
            .Width = 90
            .MaxDropDownItems = 3
            .FlatStyle = FlatStyle.Flat
        End With
        Return column
    End Function

    Private Sub SetAlternateChoicesUsingDataSource(
 _
        ByRef comboboxColumn As DataGridViewComboBoxColumn)
        With comboboxColumn
            .DataSource = RetrieveAlternativeTitles()
            .ValueMember = ColumnName.TitleOfCourtesy.ToString()
            .DisplayMember = .ValueMember
        End With
    End Sub

    Private Function RetrieveAlternativeTitles()
 As DataTable
        Return Populate( _
            "SELECT distinct TitleOfCourtesy FROM Employees")
    End Function

    Private connectionString As String
 = _
            "Integrated Security=SSPI;Persist Security Info=False;"
 _
            & "Initial Catalog=Northwind;Data Source=localhost"

    Private Function Populate(ByVal
 sqlCommand As String) As
 DataTable
        Dim northwindConnection As New
 SqlConnection(connectionString)
        northwindConnection.Open()

        Dim command As New
 SqlCommand(sqlCommand, _
            northwindConnection)
        Dim adapter As New
 SqlDataAdapter()
        adapter.SelectCommand = command
        Dim table As New
 DataTable()
        table.Locale = System.Globalization.CultureInfo.InvariantCulture
        adapter.Fill(table)

        Return table
    End Function

    Private Sub AddButtonColumn()
        Dim buttons As New
 DataGridViewButtonColumn()
        With buttons
            .HeaderText = "Sales"
            .Text = "Sales"
            .UseColumnTextForButtonValue = True
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .FlatStyle = FlatStyle.Standard
            .CellTemplate.Style.BackColor = Color.Honeydew
            .DisplayIndex = 0
        End With

        DataGridView1.Columns.Add(buttons)

    End Sub

    Private Sub AddOutOfOfficeColumn()
        Dim column As New
 DataGridViewCheckBoxColumn()
        With column
            .HeaderText = ColumnName.OutOfOffice.ToString()
            .Name = ColumnName.OutOfOffice.ToString()
            .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            .FlatStyle = FlatStyle.Standard
            .CellTemplate = New DataGridViewCheckBoxCell()
            .CellTemplate.Style.BackColor = Color.Beige
        End With

        DataGridView1.Columns.Insert(0, column)
    End Sub

    Private Sub PopulateSales( _
        ByVal buttonClick As DataGridViewCellEventArgs)

        Dim employeeId As String
 = _
            DataGridView1.Rows(buttonClick.RowIndex). _
            Cells(ColumnName.EmployeeId.ToString()).Value().ToString()
        DataGridView2.DataSource = Populate( _
            "SELECT * FROM Orders WHERE EmployeeId = "
 & employeeId)
    End Sub

#Region "SQL Error handling"
    Private Sub DataGridView1_DataError(ByVal
 sender As Object, _
    ByVal e As DataGridViewDataErrorEventArgs)
 _
    Handles DataGridView1.DataError

        MessageBox.Show("Error happened " _
            & e.Context.ToString())

        If (e.Context = DataGridViewDataErrorContexts.Commit)
 _
            Then
            MessageBox.Show("Commit error")
        End If
        If (e.Context = DataGridViewDataErrorContexts _
            .CurrentCellChange) Then
            MessageBox.Show("Cell change")
        End If
        If (e.Context = DataGridViewDataErrorContexts.Parsing)
 _
            Then
            MessageBox.Show("parsing error")
        End If
        If (e.Context = _
            DataGridViewDataErrorContexts.LeaveControl) Then
            MessageBox.Show("leave control error")
        End If

        If (TypeOf (e.Exception) Is
 ConstraintException) Then
            Dim view As DataGridView = CType(sender,
 DataGridView)
            view.Rows(e.RowIndex).ErrorText = "an error"
            view.Rows(e.RowIndex).Cells(e.ColumnIndex) _
                .ErrorText = "an error"

            e.ThrowException = False
        End If
    End Sub
#End Region

    Private Sub DataGridView1_CellContentClick(ByVal
 sender As Object, _
        ByVal e As DataGridViewCellEventArgs)
 _
        Handles DataGridView1.CellContentClick

        If IsANonHeaderLinkCell(e) Then
            MoveToLinked(e)
        ElseIf IsANonHeaderButtonCell(e) Then
            PopulateSales(e)
        End If
    End Sub

    Private Sub MoveToLinked(ByVal
 e As DataGridViewCellEventArgs)
        Dim employeeId As String
        Dim value As Object
 = DataGridView1.Rows(e.RowIndex). _
            Cells(e.ColumnIndex).Value
        If value.GetType Is GetType(DBNull)
 Then Return

        employeeId = CType(value, String)
        Dim boss As DataGridViewCell = _
            RetrieveSuperiorsLastNameCell(employeeId)
        If Not boss Is Nothing
 Then
            DataGridView1.CurrentCell = boss
        End If
    End Sub

    Private Function IsANonHeaderLinkCell(ByVal
 cellEvent As _
        DataGridViewCellEventArgs) As Boolean

        If TypeOf DataGridView1.Columns(cellEvent.ColumnIndex)
 _
            Is DataGridViewLinkColumn _
            AndAlso Not cellEvent.RowIndex
 = -1 Then _
            Return True Else
 Return False

    End Function

    Private Function IsANonHeaderButtonCell(ByVal
 cellEvent As _
        DataGridViewCellEventArgs) As Boolean

        If TypeOf DataGridView1.Columns(cellEvent.ColumnIndex)
 _
            Is DataGridViewButtonColumn _
            AndAlso Not cellEvent.RowIndex
 = -1 Then _
            Return True Else
 Return (False)

    End Function

    Private Function RetrieveSuperiorsLastNameCell(
 _
        ByVal employeeId As String)
 As DataGridViewCell

        For Each row As
 DataGridViewRow In DataGridView1.Rows
            If row.IsNewRow Then Return
 Nothing
            If row.Cells(ColumnName.EmployeeId.ToString()). _
                Value.ToString().Equals(employeeId) Then
                Return row.Cells(ColumnName.LastName.ToString())
            End If
        Next
        Return Nothing
    End Function

#Region "checkbox state"
    Dim inOffice As New
 Dictionary(Of String, Boolean)
    Private Sub DataGridView1_CellValuePushed(ByVal
 sender As Object, _
     ByVal e As DataGridViewCellValueEventArgs)
 _
        Handles DataGridView1.CellValuePushed

        If IsCheckBoxColumn(e.ColumnIndex) Then
            Dim employeeId As String
 = GetKey(e)
            If Not inOffice.ContainsKey(employeeId)
 Then
                inOffice.Add(employeeId, CType(e.Value, Boolean))
            Else
                inOffice.Item(employeeId) = CType(e.Value, Boolean)
            End If
        End If
    End Sub

    Private Function GetKey(ByVal
 cell As DataGridViewCellValueEventArgs) As
 String
        Return DataGridView1.Rows(cell.RowIndex).Cells( _
            ColumnName.EmployeeId.ToString()).Value().ToString()
    End Function

    Private Sub DataGridView1_CellValueNeeded(ByVal
 sender As Object, _
     ByVal e As DataGridViewCellValueEventArgs)
 _
        Handles DataGridView1.CellValueNeeded

        If IsCheckBoxColumn(e.ColumnIndex) Then
            Dim employeeId As String
 = GetKey(e)
            If Not inOffice.ContainsKey(employeeId)
 Then
                Dim defaultValue As Boolean
 = False
                inOffice.Add(employeeId, defaultValue)
            End If

            e.Value = inOffice.Item(employeeId)
        End If
    End Sub

    Private Function IsCheckBoxColumn(ByVal
 columnIndex As Integer) As
 Boolean
        Dim outOfOfficeColumn As DataGridViewColumn
 = _
            DataGridView1.Columns(ColumnName.OutOfOffice.ToString())
        If DataGridView1.Columns(columnIndex) Is
 outOfOfficeColumn Then
            Return True
        Else
            Return False
        End If
    End Function
#End Region

End Class
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;

public class Employees : Form
{
    private DataGridView DataGridView1 = new
 DataGridView();
    private DataGridView DataGridView2 = new
 DataGridView();

    [STAThread]
    public static void Main()
    {
        try
        {
            Application.EnableVisualStyles();
            Application.Run(new Employees());
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message + e.StackTrace);
        }
    }

    public Employees()
    {
        this.Load += new EventHandler(Form1_Load);
    }

    private void Form1_Load(System.Object sender,
 System.EventArgs e)
    {
        try
        {
            SetUpForm();
            SetUpDataGridView1();
            SetUpDataGridView2();
        }
        catch (SqlException)
        {
            MessageBox.Show("The connection string <"
                + connectionString
                + "> failed to connect.  Modify it "
                + "to connect to a Northwind database accessible to "
                + "your system.",
                "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            Application.Exit();
        }
    }

    private void SetUpForm()
    {
        Size = new Size(800, 600);
        FlowLayoutPanel flowLayout = new FlowLayoutPanel();
        flowLayout.FlowDirection = FlowDirection.TopDown;
        flowLayout.Dock = DockStyle.Fill;
        Controls.Add(flowLayout);
        Text = "DataGridView columns demo";

        flowLayout.Controls.Add(DataGridView1);
        flowLayout.Controls.Add(DataGridView2);
    }

    private void SetUpDataGridView2()
    {
        DataGridView2.Dock = DockStyle.Bottom;
        DataGridView2.TopLeftHeaderCell.Value = "Sales Details";
        DataGridView2.RowHeadersWidthSizeMode = 
            DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
    }

    private void SetUpDataGridView1()
    {
        DataGridView1.DataError += new 
            DataGridViewDataErrorEventHandler(DataGridView1_DataError);
        DataGridView1.CellContentClick += new 
            DataGridViewCellEventHandler(DataGridView1_CellContentClick);
        DataGridView1.CellValuePushed += new 
            DataGridViewCellValueEventHandler(DataGridView1_CellValuePushed);
        DataGridView1.CellValueNeeded += new 
            DataGridViewCellValueEventHandler(DataGridView1_CellValueNeeded);

        // Virtual mode is turned on so that the
        // unbound DataGridViewCheckBoxColumn will
        // keep its state when the bound columns are
        // sorted.       
        DataGridView1.VirtualMode = true;
        DataGridView1.AutoSize = true;
        DataGridView1.DataSource = Populate("SELECT * FROM Employees");
        DataGridView1.TopLeftHeaderCell.Value = "Employees";
        DataGridView1.RowHeadersWidthSizeMode = 
            DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
        DataGridView1.ColumnHeadersHeightSizeMode = 
            DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        DataGridView1.AutoSizeColumnsMode = 
            DataGridViewAutoSizeColumnsMode.AllCells;
        DataGridView1.AllowUserToAddRows = false;
        DataGridView1.AllowUserToDeleteRows = false;

        // The below autogenerated column is removed so 
        // a DataGridViewComboboxColumn could be used instead.
        DataGridView1.Columns.Remove(ColumnName.TitleOfCourtesy.ToString());
        DataGridView1.Columns.Remove(ColumnName.ReportsTo.ToString());

        AddLinkColumn();
        AddComboBoxColumns();
        AddButtonColumn();
        AddOutOfOfficeColumn();
    }

    // Using an enum provides some abstraction between column index
    // and column name along with compile time checking, and gives
    // a handy place to store the column names.
    enum ColumnName
    {
        EmployeeId,
        LastName,
        FirstName,
        Title,
        TitleOfCourtesy,
        BirthDate,
        HireDate,
        Address,
        City,
        Region,
        PostalCode,
        Country,
        HomePhone,
        Extension,
        Photo,
        Notes,
        ReportsTo,
        PhotoPath,
        OutOfOffice
    };

    private void AddComboBoxColumns()
    {
        DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
        comboboxColumn = CreateComboBoxColumn();
        SetAlternateChoicesUsingDataSource(ref comboboxColumn);
        comboboxColumn.HeaderText = "TitleOfCourtesy (via DataSource property)";
        DataGridView1.Columns.Insert(0, comboboxColumn);

        comboboxColumn = CreateComboBoxColumn();
        SetAlternateChoicesUsingItems(ref comboboxColumn);
        comboboxColumn.HeaderText = "TitleOfCourtesy (via Items property)";
        // Tack this example column onto the end.
        DataGridView1.Columns.Add(comboboxColumn);
    }

    private void AddLinkColumn()
    {
        DataGridViewLinkColumn links = new DataGridViewLinkColumn();

        links.HeaderText = ColumnName.ReportsTo.ToString();
        links.DataPropertyName = ColumnName.ReportsTo.ToString();
        links.ActiveLinkColor = Color.White;
        links.LinkBehavior = LinkBehavior.SystemDefault;
        links.LinkColor = Color.Blue;
        links.TrackVisitedState = true;
        links.VisitedLinkColor = Color.YellowGreen;

        DataGridView1.Columns.Add(links);
    }

    private static void
 SetAlternateChoicesUsingItems(
        ref DataGridViewComboBoxColumn comboboxColumn)
    {
        {
            comboboxColumn.Items.AddRange(
                new string[] { "Mr.",
 "Ms.", "Mrs.", "Dr." });
        }
    }

    private DataGridViewComboBoxColumn CreateComboBoxColumn()
    {
        DataGridViewComboBoxColumn column =
            new DataGridViewComboBoxColumn();
        {
            column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
            column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
            column.DropDownWidth = 160;
            column.Width = 90;
            column.MaxDropDownItems = 3;
            column.FlatStyle = FlatStyle.Flat;
        }
        return column;
    }

    private void SetAlternateChoicesUsingDataSource(ref
 DataGridViewComboBoxColumn comboboxColumn)
    {
        {
            comboboxColumn.DataSource = RetrieveAlternativeTitles();
            comboboxColumn.ValueMember = ColumnName.TitleOfCourtesy.ToString();
            comboboxColumn.DisplayMember = comboboxColumn.ValueMember;
        }
    }

    private DataTable RetrieveAlternativeTitles()
    {
        return Populate("SELECT distinct TitleOfCourtesy
 FROM Employees");
    }

    string connectionString =
        "Integrated Security=SSPI;Persist Security Info=False;" +
        "Initial Catalog=Northwind;Data Source=localhost";

    private DataTable Populate(string sqlCommand)
    {
        SqlConnection northwindConnection = new SqlConnection(connectionString);
        northwindConnection.Open();

        SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = command;

        DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        adapter.Fill(table);

        return table;
    }

    private void AddButtonColumn()
    {
        DataGridViewButtonColumn buttons = new DataGridViewButtonColumn();
        {
            buttons.HeaderText = "Sales";
            buttons.Text = "Sales";
            buttons.UseColumnTextForButtonValue = true;
            buttons.AutoSizeMode =
                DataGridViewAutoSizeColumnMode.AllCells;
            buttons.FlatStyle = FlatStyle.Standard;
            buttons.CellTemplate.Style.BackColor = Color.Honeydew;
            buttons.DisplayIndex = 0;
        }

        DataGridView1.Columns.Add(buttons);

    }

    private void AddOutOfOfficeColumn()
    {
        DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
        {
            column.HeaderText = ColumnName.OutOfOffice.ToString();
            column.Name = ColumnName.OutOfOffice.ToString();
            column.AutoSizeMode = 
                DataGridViewAutoSizeColumnMode.DisplayedCells;
            column.FlatStyle = FlatStyle.Standard;
            column.ThreeState = true;
            column.CellTemplate = new DataGridViewCheckBoxCell();
            column.CellTemplate.Style.BackColor = Color.Beige;
        }

        DataGridView1.Columns.Insert(0, column);
    }

    private void PopulateSales(DataGridViewCellEventArgs
 buttonClick)
    {

        string employeeId = DataGridView1.Rows[buttonClick.RowIndex]
            .Cells[ColumnName.EmployeeId.ToString()].Value.ToString();
        DataGridView2.DataSource = Populate("SELECT * FROM Orders WHERE EmployeeId
 = " + employeeId);
    }

    #region "SQL Error handling"
    private void DataGridView1_DataError(object
 sender, DataGridViewDataErrorEventArgs anError)
    {

        MessageBox.Show("Error happened " + anError.Context.ToString());

        if (anError.Context == DataGridViewDataErrorContexts.Commit)
        {
            MessageBox.Show("Commit error");
        }
        if (anError.Context == DataGridViewDataErrorContexts.CurrentCellChange)
        {
            MessageBox.Show("Cell change");
        }
        if (anError.Context == DataGridViewDataErrorContexts.Parsing)
        {
            MessageBox.Show("parsing error");
        }
        if (anError.Context == DataGridViewDataErrorContexts.LeaveControl)
        {
            MessageBox.Show("leave control error");
        }

        if ((anError.Exception) is ConstraintException)
        {
            DataGridView view = (DataGridView)sender;
            view.Rows[anError.RowIndex].ErrorText = "an error";
            view.Rows[anError.RowIndex].Cells[anError.ColumnIndex].ErrorText = "an
 error";

            anError.ThrowException = false;
        }
    }
    #endregion

    private void DataGridView1_CellContentClick(object
 sender, DataGridViewCellEventArgs e)
    {

        if (IsANonHeaderLinkCell(e))
        {
            MoveToLinked(e);
        }
        else if (IsANonHeaderButtonCell(e))
        {
            PopulateSales(e);
        }
    }

    private void MoveToLinked(DataGridViewCellEventArgs
 e)
    {
        string employeeId;
        object value = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
        if (value is DBNull) { return; }

        employeeId = value.ToString();
        DataGridViewCell boss = RetrieveSuperiorsLastNameCell(employeeId);
        if (boss != null)
        {
            DataGridView1.CurrentCell = boss;
        }
    }

    private bool IsANonHeaderLinkCell(DataGridViewCellEventArgs
 cellEvent)
    {
        if (DataGridView1.Columns[cellEvent.ColumnIndex] is
            DataGridViewLinkColumn &&
            cellEvent.RowIndex != -1)
        { return true; }
        else { return false;
 }
    }

    private bool IsANonHeaderButtonCell(DataGridViewCellEventArgs
 cellEvent)
    {
        if (DataGridView1.Columns[cellEvent.ColumnIndex] is
            DataGridViewButtonColumn &&
            cellEvent.RowIndex != -1)
        { return true; }
        else { return (false);
 }
    }

    private DataGridViewCell RetrieveSuperiorsLastNameCell(string
 employeeId)
    {

        foreach (DataGridViewRow row in DataGridView1.Rows)
        {
            if (row.IsNewRow) { return null;
 }
            if (row.Cells[ColumnName.EmployeeId.ToString()].Value.ToString().Equals(employeeId))
            {
                return row.Cells[ColumnName.LastName.ToString()];
            }
        }
        return null;
    }

    #region "checkbox state"
    Dictionary<string, bool> inOffice
 = new Dictionary<string, bool>();
    private void DataGridView1_CellValuePushed(object
 sender,
        DataGridViewCellValueEventArgs e)
    {
        if (IsCheckBoxColumn(e.ColumnIndex))
        {
            string employeeId = GetKey(e);
            if (!inOffice.ContainsKey(employeeId))
            {
                inOffice.Add(employeeId, (Boolean)e.Value);
            }
            else
            {
                inOffice[employeeId] = (Boolean)e.Value;
            }
        }
    }

    private string GetKey(DataGridViewCellValueEventArgs
 cell)
    {
        return DataGridView1.Rows[cell.RowIndex].
            Cells[ColumnName.EmployeeId.ToString()].Value.ToString();
    }

    private void DataGridView1_CellValueNeeded(object
 sender,
        DataGridViewCellValueEventArgs e)
    {

        if (IsCheckBoxColumn(e.ColumnIndex))
        {
            string employeeId = GetKey(e);
            if (!inOffice.ContainsKey(employeeId))
            {
                bool defaultValue = false;
                inOffice.Add(employeeId, defaultValue);
            }

            e.Value = inOffice[employeeId];
        }
    }

    private bool IsCheckBoxColumn(int
 columnIndex)
    {
        DataGridViewColumn outOfOfficeColumn =
            DataGridView1.Columns[ColumnName.OutOfOffice.ToString()];
        if (DataGridView1.Columns[columnIndex] == outOfOfficeColumn)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    #endregion
}
#using <System.Data.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>

#using <System.Xml.dll>
#using <System.EnterpriseServices.dll>
#using <System.Transactions.dll>
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
using namespace System::Windows::Forms;
using namespace System::Collections::Generic;
using namespace System::Drawing;

public ref class Employees : public
 Form
{
private:
    DataGridView^ DataGridView1;

private:
    DataGridView^ DataGridView2;

public:
    [STAThread]
    static void Main()
    {
        try
        {
            Application::EnableVisualStyles();
            Application::Run(gcnew Employees());
        }
        catch (Exception^ e)
        {
            MessageBox::Show(e->Message + e->StackTrace);
        }
    }

private:
    Dictionary<String^, bool>^ inOffice;

public:
    Employees()
    {
        DataGridView1 = gcnew DataGridView();
        DataGridView2 = gcnew DataGridView();
        connectionString =
            "Integrated Security=SSPI;Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";
        inOffice = gcnew Dictionary<String^, bool>;

        this->Load += gcnew EventHandler(this,
 &Employees::Form1_Load);
    }

private:
    void Form1_Load(System::Object^ /*sender*/, System::EventArgs^
 /*e*/)
    {
        try
        {
            SetUpForm();
            SetUpDataGridView1();
            SetUpDataGridView2();
        }
        catch (SqlException^)
        {
            MessageBox::Show("The connection string <"
                + connectionString
                + "> failed to connect.  Modify it "
                + "to connect to a Northwind database accessible to "
                + "your system.",
                "ERROR", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
            Application::Exit();
        }
    }

private:
    void SetUpForm()
    {
        Size = System::Drawing::Size(800, 600);
        FlowLayoutPanel^ flowLayout = gcnew FlowLayoutPanel();
        flowLayout->FlowDirection = FlowDirection::TopDown;
        flowLayout->Dock = DockStyle::Fill;
        Controls->Add(flowLayout);

        flowLayout->Controls->Add(DataGridView1);
        flowLayout->Controls->Add(DataGridView2);
    }

private:
    void SetUpDataGridView2()
    {
        DataGridView2->Dock = DockStyle::Bottom;
        DataGridView2->TopLeftHeaderCell->Value = "Sales Details";
        DataGridView2->RowHeadersWidthSizeMode = 
            DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders;
    }

private:
    void SetUpDataGridView1()
    {
        //DataGridView1.DataError += new 
          //  DataGridViewDataErrorEventHandler(DataGridView1_DataError);
        DataGridView1->CellContentClick += gcnew 
            DataGridViewCellEventHandler(this, &Employees::DataGridView1_CellContentClick);
        DataGridView1->CellValuePushed += gcnew 
            DataGridViewCellValueEventHandler(this, &Employees::DataGridView1_CellValuePushed);
        DataGridView1->CellValueNeeded += gcnew 
            DataGridViewCellValueEventHandler(this, &Employees::DataGridView1_CellValueNeeded);

        // Virtual mode is turned on so that the
        // unbound DataGridViewCheckBoxColumn will
        // keep its state when the bound columns are
        // sorted.       
        DataGridView1->VirtualMode = true;
        DataGridView1->AutoSize = true;
        DataGridView1->DataSource = Populate("SELECT * FROM Employees");
        DataGridView1->TopLeftHeaderCell->Value = "Employees";
        DataGridView1->RowHeadersWidthSizeMode = 
            DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders;
        DataGridView1->ColumnHeadersHeightSizeMode = 
            DataGridViewColumnHeadersHeightSizeMode::AutoSize;
        DataGridView1->AutoSizeColumnsMode = 
            DataGridViewAutoSizeColumnsMode::AllCells;
        DataGridView1->AllowUserToAddRows = false;
        DataGridView1->AllowUserToDeleteRows = false;

        // The below autogenerated column is removed so 
        // a DataGridViewComboboxColumn could be used instead.
        DataGridView1->Columns->Remove(ColumnName::TitleOfCourtesy.ToString());
        DataGridView1->Columns->Remove(ColumnName::ReportsTo.ToString());

        AddLinkColumn();
        AddComboBoxColumns();
        AddButtonColumn();
        AddOutOfOfficeColumn();
    }

    // Using an enum provides some abstraction between column index
    // and column name along with compile time checking, and gives
    // a handy place to store the column names.
    enum class ColumnName
    {
        EmployeeID,
        LastName,
        FirstName,
        Title,
        TitleOfCourtesy,
        BirthDate,
        HireDate,
        Address,
        City,
        Region,
        PostalCode,
        Country,
        HomePhone,
        Extension,
        Photo,
        Notes,
        ReportsTo,
        PhotoPath,
        OutOfOffice
    };

private:
    void AddComboBoxColumns()
    {
        DataGridViewComboBoxColumn^ comboboxColumn = gcnew DataGridViewComboBoxColumn();
        comboboxColumn = CreateComboBoxColumn();
        SetAlternateChoicesUsingDataSource(comboboxColumn);
        comboboxColumn->HeaderText = "TitleOfCourtesy (via DataSource property)";
        DataGridView1->Columns->Insert(0, comboboxColumn);

        comboboxColumn = CreateComboBoxColumn();
        SetAlternateChoicesUsingItems(comboboxColumn);
        comboboxColumn->HeaderText = "TitleOfCourtesy (via Items property)";
        // Tack this example column onto the end.
        DataGridView1->Columns->Add(comboboxColumn);
    }

private:
    void AddLinkColumn()
    {
        DataGridViewLinkColumn^ links = gcnew DataGridViewLinkColumn();

        links->HeaderText = ColumnName::ReportsTo.ToString();
        links->DataPropertyName = ColumnName::ReportsTo.ToString();
        links->ActiveLinkColor = Color::White;
        links->LinkBehavior = LinkBehavior::SystemDefault;
        links->LinkColor = Color::Blue;
        links->TrackVisitedState = true;
        links->VisitedLinkColor = Color::YellowGreen;

        DataGridView1->Columns->Add(links);
    }

private:
    void SetAlternateChoicesUsingItems(
        DataGridViewComboBoxColumn^% comboboxColumn)
    {
        {
            comboboxColumn->Items->AddRange(
                gcnew array<String^> { "Mr.", "Ms.", "Mrs.",
 "Dr." });
        }
    }

private:
    DataGridViewComboBoxColumn^ CreateComboBoxColumn()
    {
        DataGridViewComboBoxColumn^ column =
            gcnew DataGridViewComboBoxColumn();
        {
            column->DataPropertyName = ColumnName::TitleOfCourtesy.ToString();
            column->HeaderText = ColumnName::TitleOfCourtesy.ToString();
            column->DropDownWidth = 160;
            column->Width = 90;
            column->MaxDropDownItems = 3;
            column->FlatStyle = FlatStyle::Flat;
        }
        return column;
    }

private:
    void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn^%
 comboboxColumn)
    {
        {
            comboboxColumn->DataSource = RetrieveAlternativeTitles();
            comboboxColumn->ValueMember = ColumnName::TitleOfCourtesy.ToString();
            comboboxColumn->DisplayMember = comboboxColumn->ValueMember;
        }
    }

private:
    DataTable^ RetrieveAlternativeTitles()
    {
        return Populate("SELECT distinct TitleOfCourtesy
 FROM Employees");
    }

    String^ connectionString;

private:
    DataTable^ Populate(String^ sqlCommand)
    {
        SqlConnection^ northwindConnection = gcnew SqlConnection(connectionString);
        northwindConnection->Open();

        SqlCommand^ command = gcnew SqlCommand(sqlCommand, northwindConnection);
        SqlDataAdapter^ adapter = gcnew SqlDataAdapter();
        adapter->SelectCommand = command;

        DataTable^ table = gcnew DataTable();
        adapter->Fill(table);

        return table;
    }

private:
    void AddButtonColumn()
    {
        DataGridViewButtonColumn^ buttons = gcnew DataGridViewButtonColumn();
        {
            buttons->HeaderText = "Sales";
            buttons->Text = "Sales";
            buttons->UseColumnTextForButtonValue = true;
            buttons->AutoSizeMode =
                DataGridViewAutoSizeColumnMode::AllCells;
            buttons->FlatStyle = FlatStyle::Standard;
            buttons->CellTemplate->Style->BackColor = Color::Honeydew;
            buttons->DisplayIndex = 0;
        }

        DataGridView1->Columns->Add(buttons);

    }

private:
    void AddOutOfOfficeColumn()
    {
        DataGridViewCheckBoxColumn^ column = gcnew DataGridViewCheckBoxColumn();
        {
            column->HeaderText = ColumnName::OutOfOffice.ToString();
            column->Name = ColumnName::OutOfOffice.ToString();
            column->AutoSizeMode = 
                DataGridViewAutoSizeColumnMode::DisplayedCells;
            column->FlatStyle = FlatStyle::Standard;
            column->ThreeState = true;
            column->CellTemplate = gcnew DataGridViewCheckBoxCell();
            column->CellTemplate->Style->BackColor = Color::Beige;
        }

        DataGridView1->Columns->Insert(0, column);
    }

private:
    void PopulateSales(DataGridViewCellEventArgs^ buttonClick)
    {

        String^ employeeID = DataGridView1->Rows[buttonClick->RowIndex]
            ->Cells[ColumnName::EmployeeID.ToString()]->Value->ToString();
        DataGridView2->DataSource = Populate("SELECT * FROM Orders WHERE
 EmployeeID = " + employeeID);
    }

    #pragma region "SQL Error handling"
private:
    void DataGridView1_DataError(Object^ sender, DataGridViewDataErrorEventArgs^
 anError)
    {

        MessageBox::Show("Error happened " + anError->Context.ToString());

        if (anError->Context == DataGridViewDataErrorContexts::Commit)
        {
            MessageBox::Show("Commit error");
        }
        if (anError->Context == DataGridViewDataErrorContexts::CurrentCellChange)
        {
            MessageBox::Show("Cell change");
        }
        if (anError->Context == DataGridViewDataErrorContexts::Parsing)
        {
            MessageBox::Show("parsing error");
        }
        if (anError->Context == DataGridViewDataErrorContexts::LeaveControl)
        {
            MessageBox::Show("leave control error");
        }

        if (dynamic_cast<ConstraintException^>(anError->Exception)
 != nullptr)
        {
            DataGridView^ view = (DataGridView^)sender;
            view->Rows[anError->RowIndex]->ErrorText = "an error";
            view->Rows[anError->RowIndex]->Cells[anError->ColumnIndex]->ErrorText
 = "an error";

            anError->ThrowException = false;
        }
    }
    #pragma endregion

private:
    void DataGridView1_CellContentClick(Object^ /*sender*/, DataGridViewCellEventArgs^
 e)
    {

        if (IsANonHeaderLinkCell(e))
        {
            MoveToLinked(e);
        }
        else if (IsANonHeaderButtonCell(e))
        {
            PopulateSales(e);
        }
    }

private:
    void MoveToLinked(DataGridViewCellEventArgs^ e)
    {
        String^ employeeId;
        Object^ value = DataGridView1->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value;
        if (dynamic_cast<DBNull^>(value) != nullptr) { return;
 }

        employeeId = value->ToString();
        DataGridViewCell^ boss = RetrieveSuperiorsLastNameCell(employeeId);
        if (boss != nullptr)
        {
            DataGridView1->CurrentCell = boss;
        }
    }

private:
    bool IsANonHeaderLinkCell(DataGridViewCellEventArgs^ cellEvent)
    {
        if (dynamic_cast<DataGridViewLinkColumn^>(DataGridView1->Columns[cellEvent->ColumnIndex])
 != nullptr
             &&
            cellEvent->RowIndex != -1)
        { return true; }
        else { return false;
 }
    }

private:
    bool IsANonHeaderButtonCell(DataGridViewCellEventArgs^ cellEvent)
    {
        if (dynamic_cast<DataGridViewButtonColumn^>(DataGridView1->Columns[cellEvent->ColumnIndex])
 != nullptr
             &&
            cellEvent->RowIndex != -1)
        { return true; }
        else { return (false);
 }
    }

private:
    DataGridViewCell^ RetrieveSuperiorsLastNameCell(String^ employeeId)
    {

        for each (DataGridViewRow^ row in DataGridView1->Rows)
        {
            if (row->IsNewRow) { return
 nullptr; }
            if (row->Cells[ColumnName::EmployeeID.ToString()]->Value->ToString()->Equals(employeeId))
            {
                return row->Cells[ColumnName::LastName.ToString()];
            }
        }
        return nullptr;
    }

    #pragma region "checkbox state"

private:
    void DataGridView1_CellValuePushed(Object^ sender,
        DataGridViewCellValueEventArgs^ e)
    {
        if (IsCheckBoxColumn(e->ColumnIndex))
        {
            String^ employeeId = GetKey(e);
            if (!inOffice->ContainsKey(employeeId))
            {
                inOffice->Add(employeeId, (Boolean)e->Value);
            }
            else
            {
                inOffice[employeeId] = (Boolean)e->Value;
            }
        }
    }

private:
    String^ GetKey(DataGridViewCellValueEventArgs^ cell)
    {
        return DataGridView1->Rows[cell->RowIndex]->
            Cells[ColumnName::EmployeeID.ToString()]->Value->ToString();
    }

private:
    void DataGridView1_CellValueNeeded(Object^ sender,
        DataGridViewCellValueEventArgs^ e)
    {

        if (IsCheckBoxColumn(e->ColumnIndex))
        {
            String^ employeeId = GetKey(e);
            if (!inOffice->ContainsKey(employeeId))
            {
                bool defaultValue = false;
                inOffice->Add(employeeId, defaultValue);
            }

            e->Value = inOffice[employeeId];
        }
    }

private:
    bool IsCheckBoxColumn(int columnIndex)
    {
        DataGridViewColumn^ outOfOfficeColumn =
            DataGridView1->Columns[ColumnName::OutOfOffice.ToString()];
        if (DataGridView1->Columns[columnIndex] == outOfOfficeColumn)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    #pragma endregion
};

int main()
{
    Employees::Main();
}
継承階層継承階層
System.Object
   System.Windows.Forms.DataGridViewElement
     System.Windows.Forms.DataGridViewBand
       System.Windows.Forms.DataGridViewColumn
        System.Windows.Forms.DataGridViewComboBoxColumn
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewComboBoxColumn メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.DataSource プロパティ
DataGridViewColumn.DataPropertyName プロパティ
DataSource
Items
ValueMember
DisplayMember
DataGridViewColumn クラス
DataGridViewRow
DataGridViewComboBoxCell クラス
DataGridViewComboBoxEditingControl
DataGridViewColumn.SortMode プロパティ

DataGridViewComboBoxColumn コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

DataGridViewTextBoxColumn クラスの新しいインスタンスを既定の状態に初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Dim instance As New DataGridViewComboBoxColumn
public DataGridViewComboBoxColumn ()
public:
DataGridViewComboBoxColumn ()
public DataGridViewComboBoxColumn ()
public function DataGridViewComboBoxColumn
 ()
解説解説

このコンストラクタは、DataGridViewComboBoxColumn の新しいインスタンスを初期化するときに、CellTemplate プロパティを新しい DataGridViewComboBoxCell インスタンスに設定します。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewComboBoxColumn クラス
DataGridViewComboBoxColumn メンバ
System.Windows.Forms 名前空間
DataGridView クラス
CellTemplate
DataGridViewComboBoxCell クラス

DataGridViewComboBoxColumn プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ AutoComplete 列内のセルで、セル内に入力される文字と、入力される可能性のある選択項目のうちの 1 つを一致させるかどうかを示す値を取得または設定します。
パブリック プロパティ AutoSizeMode  列の幅を自動的に調整するときに使用するモードを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ CellTemplate オーバーライドされます。 セルの作成に使用するテンプレートを取得または設定します。
パブリック プロパティ CellType  セル テンプレートのランタイム型を取得します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ ContextMenuStrip  列のショートカット メニューを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ DataGridView  この要素に関連付けられている DataGridView コントロールを取得します。 ( DataGridViewElement から継承されます。)
パブリック プロパティ DataPropertyName  DataGridViewColumn がバインドされている、データ ソース プロパティの名前またはデータベースの列の名前を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ DataSource コンボ ボックスの選択項目を決定するデータ ソースを取得または設定します。
パブリック プロパティ DefaultCellStyle  列の既定のセル スタイルを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ DefaultHeaderCellType  既定のヘッダー セルのランタイム型を取得または設定します。 ( DataGridViewBand から継承されます。)
パブリック プロパティ Displayed  バンドが現在画面に表示されているかどうかを示す値を取得します。 ( DataGridViewBand から継承されます。)
パブリック プロパティ DisplayIndex  現在表示されている列を基準とした列の表示順序を設定または取得します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ DisplayMember コンボ ボックスに表示する文字列の取得先となるプロパティまたは列を指定する文字列を取得または設定します。
パブリック プロパティ DisplayStyle 編集時以外にコンボ ボックスを表示する方法を決定する値を取得または設定します。
パブリック プロパティ DisplayStyleForCurrentCellOnly この列に現在のセルが含まれる場合に、DisplayStyle プロパティの値を DataGridView コントロールの現在のセルにのみ適用するかどうかを示す値を取得または設定します。
パブリック プロパティ DividerWidth  列の区分線の幅 (ピクセル数) を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ DropDownWidth コンボ ボックスのドロップダウン リストの幅を取得または設定します。
パブリック プロパティ FillWeight  列が、コントロール内の他の塗りつぶしモードの列の幅を基準とする塗りつぶしモードの場合、列の幅を表す値を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ FlatStyle 列に含まれるセルのフラット スタイルの外観を取得または設定します。
パブリック プロパティ Frozen  ユーザーが DataGridView コントロールを水平方向にスクロールしたときに列が移動するかどうかを示す値を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ HasDefaultCellStyle  DefaultCellStyle プロパティが設定されているかどうかを示す値を取得します。 ( DataGridViewBand から継承されます。)
パブリック プロパティ HeaderCell  列ヘッダーを表す DataGridViewColumnHeaderCell を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ HeaderText  列のヘッダー セルのキャプション テキストを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Index  DataGridView コントロール内のバンドの相対位置を取得します。 ( DataGridViewBand から継承されます。)
パブリック プロパティ InheritedAutoSizeMode  列に対して有効なサイズ変更モードを取得します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ InheritedStyle  列に現在適用されているセル スタイルを取得します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ IsDataBound  列がデータ ソースにバインドされているかどうかを示す値を取得します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Items コンボ ボックスの選択項目として使用されるオブジェクトのコレクションを取得します。
パブリック プロパティ MaxDropDownItems 列内のセルのドロップダウン リストに表示する項目の最大数を取得または設定します。
パブリック プロパティ MinimumWidth  列の最小幅をピクセル単位で取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Name  列の名前を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ ReadOnly  ユーザーが列のセルを編集できるかどうかを示す値を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Resizable  列のサイズを変更できるかどうかを示す値を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Selected  バンドが、選択されたユーザー インターフェイス (UI) 状態かどうかを示す値を取得または設定します。 ( DataGridViewBand から継承されます。)
パブリック プロパティ Site  列のサイトを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Sorted コンボ ボックス内の項目が並べ替えられたかどうかを示す値を取得または設定します。
パブリック プロパティ SortMode  列の並べ替えモードを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ State  要素のユーザー インターフェイス (UI) の状態を取得します。 ( DataGridViewElement から継承されます。)
パブリック プロパティ Tag  バンドに関連付けられているデータを含むオブジェクトを取得または設定します。 ( DataGridViewBand から継承されます。)
パブリック プロパティ ToolTipText  ツールヒントに使用されるテキストを取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ ValueMember ドロップダウン リストの選択項目に対応する値の取得先となる、プロパティまたは列を指定する文字列を取得または設定します。
パブリック プロパティ ValueType  列のセルの値のデータ型を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Visible  列を表示するかどうかを示す値を取得または設定します。 ( DataGridViewColumn から継承されます。)
パブリック プロパティ Width  列の現在の幅を取得または設定します。 ( DataGridViewColumn から継承されます。)
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HeaderCellCore  DataGridViewBand のヘッダー セルを取得または設定します。 ( DataGridViewBand から継承されます。)
プロテクト プロパティ IsRow  バンドが行を表すかどうかを示す値を取得します。 ( DataGridViewBand から継承されます。)
参照参照

関連項目

DataGridViewComboBoxColumn クラス
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.DataSource プロパティ
DataGridViewColumn.DataPropertyName プロパティ
DataSource
Items
ValueMember
DisplayMember
DataGridViewColumn クラス
DataGridViewRow
DataGridViewComboBoxCell クラス
DataGridViewComboBoxEditingControl
DataGridViewColumn.SortMode プロパティ

DataGridViewComboBoxColumn メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
  名前 説明
プロテクト メソッド Dispose  オーバーロードされます。 DataGridViewColumn によって使用されているすべてのリソースを解放します。 ( DataGridViewColumn から継承されます。)
プロテクト メソッド Finalize  バンドに関連付けられたリソースを解放します。 ( DataGridViewBand から継承されます。)
プロテクト メソッド MemberwiseClone  現在の Object の簡易コピーを作成します。 ( Object から継承されます。)
プロテクト メソッド OnDataGridViewChanged  バンドが別の DataGridView に関連付けられている場合に呼び出されます。 ( DataGridViewBand から継承されます。)
プロテクト メソッド RaiseCellClick  DataGridView.CellClick イベントを発生させます。 ( DataGridViewElement から継承されます。)
プロテクト メソッド RaiseCellContentClick  DataGridView.CellContentClick イベントを発生させます。 ( DataGridViewElement から継承されます。)
プロテクト メソッド RaiseCellContentDoubleClick  DataGridView.CellContentDoubleClick イベントを発生させます。 ( DataGridViewElement から継承されます。)
プロテクト メソッド RaiseCellValueChanged  DataGridView.CellValueChanged イベントを発生させます。 ( DataGridViewElement から継承されます。)
プロテクト メソッド RaiseDataError  DataGridView.DataError イベントを発生させます。 ( DataGridViewElement から継承されます。)
プロテクト メソッド RaiseMouseWheel  Control.MouseWheel イベントを発生させます。 ( DataGridViewElement から継承されます。)
参照参照

関連項目

DataGridViewComboBoxColumn クラス
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.DataSource プロパティ
DataGridViewColumn.DataPropertyName プロパティ
DataSource
Items
ValueMember
DisplayMember
DataGridViewColumn クラス
DataGridViewRow
DataGridViewComboBoxCell クラス
DataGridViewComboBoxEditingControl
DataGridViewColumn.SortMode プロパティ

DataGridViewComboBoxColumn メンバ

DataGridViewComboBoxCell オブジェクトの列を表します。

DataGridViewComboBoxColumn データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DataGridViewComboBoxColumn DataGridViewTextBoxColumn クラスの新しいインスタンスを既定の状態に初期化します。
パブリック プロパティパブリック プロパティ
( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ AutoComplete 列内のセルで、セル内に入力される文字と、入力される可能性のある選択項目のうちの 1 つを一致させるかどうかを示す値を取得または設定します。
パブリック プロパティ AutoSizeMode  列の幅を自動的に調整するときに使用するモードを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ CellTemplate オーバーライドされます。 セルの作成に使用するテンプレートを取得または設定します。
パブリック プロパティ CellType  セル テンプレートのランタイム型を取得します。(DataGridViewColumn から継承されます。)
パブリック プロパティ ContextMenuStrip  列のショートカット メニューを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ DataGridView  この要素に関連付けられている DataGridView コントロールを取得します。(DataGridViewElement から継承されます。)
パブリック プロパティ DataPropertyName  DataGridViewColumn がバインドされている、データ ソース プロパティの名前またはデータベースの列の名前を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ DataSource コンボ ボックスの選択項目を決定するデータ ソースを取得または設定します。
パブリック プロパティ DefaultCellStyle  列の既定のセル スタイルを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ DefaultHeaderCellType  既定のヘッダー セルのランタイム型を取得または設定します。(DataGridViewBand から継承されます。)
パブリック プロパティ Displayed  バンドが現在画面に表示されているかどうかを示す値を取得します。 (DataGridViewBand から継承されます。)
パブリック プロパティ DisplayIndex  現在表示されている列を基準とした列の表示順序を設定または取得します。(DataGridViewColumn から継承されます。)
パブリック プロパティ DisplayMember コンボ ボックスに表示する文字列の取得先となるプロパティまたは列を指定する文字列を取得または設定します。
パブリック プロパティ DisplayStyle 編集時以外にコンボ ボックスを表示する方法を決定する値を取得または設定します。
パブリック プロパティ DisplayStyleForCurrentCellOnly この列に現在のセルが含まれる場合に、DisplayStyle プロパティの値を DataGridView コントロールの現在のセルにのみ適用するかどうかを示す値を取得または設定します。
パブリック プロパティ DividerWidth  列の区分線の幅 (ピクセル数) を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ DropDownWidth コンボ ボックスのドロップダウン リストの幅を取得または設定します。
パブリック プロパティ FillWeight  列が、コントロール内の他の塗りつぶしモードの列の幅を基準とする塗りつぶしモードの場合、列の幅を表す値を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ FlatStyle 列に含まれるセルのフラット スタイルの外観を取得または設定します。
パブリック プロパティ Frozen  ユーザーが DataGridView コントロールを水平方向にスクロールしたときに列が移動するかどうかを示す値を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ HasDefaultCellStyle  DefaultCellStyle プロパティが設定されているかどうかを示す値を取得します。 (DataGridViewBand から継承されます。)
パブリック プロパティ HeaderCell  列ヘッダーを表す DataGridViewColumnHeaderCell を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ HeaderText  列のヘッダー セルのキャプション テキストを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Index  DataGridView コントロール内のバンドの相対位置を取得します。(DataGridViewBand から継承されます。)
パブリック プロパティ InheritedAutoSizeMode  列に対して有効なサイズ変更モードを取得します。(DataGridViewColumn から継承されます。)
パブリック プロパティ InheritedStyle  列に現在適用されているセル スタイルを取得します。(DataGridViewColumn から継承されます。)
パブリック プロパティ IsDataBound  列がデータ ソースにバインドされているかどうかを示す値を取得します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Items コンボ ボックスの選択項目として使用されるオブジェクトのコレクションを取得します。
パブリック プロパティ MaxDropDownItems 列内のセルのドロップダウン リストに表示する項目の最大数を取得または設定します。
パブリック プロパティ MinimumWidth  列の最小幅をピクセル単位で取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Name  列の名前を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ ReadOnly  ユーザーが列のセルを編集できるかどうかを示す値を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Resizable  列のサイズを変更できるかどうかを示す値を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Selected  バンドが、選択されたユーザー インターフェイス (UI) 状態かどうかを示す値を取得または設定します。(DataGridViewBand から継承されます。)
パブリック プロパティ Site  列のサイトを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Sorted コンボ ボックス内の項目が並べ替えられたかどうかを示す値を取得または設定します。
パブリック プロパティ SortMode  列の並べ替えモードを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ State  要素のユーザー インターフェイス (UI) の状態を取得します。(DataGridViewElement から継承されます。)
パブリック プロパティ Tag  バンドに関連付けられているデータを含むオブジェクトを取得または設定します。(DataGridViewBand から継承されます。)
パブリック プロパティ ToolTipText  ツールヒントに使用されるテキストを取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ ValueMember ドロップダウン リストの選択項目に対応する値の取得先となる、プロパティまたは列を指定する文字列を取得または設定します。
パブリック プロパティ ValueType  列のセルの値のデータ型を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Visible  列を表示するかどうかを示す値を取得または設定します。(DataGridViewColumn から継承されます。)
パブリック プロパティ Width  列の現在の幅を取得または設定します。(DataGridViewColumn から継承されます。)
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HeaderCellCore  DataGridViewBand のヘッダー セルを取得または設定します。(DataGridViewBand から継承されます。)
プロテクト プロパティ IsRow  バンドが行を表すかどうかを示す値を取得します。(DataGridViewBand から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
  名前 説明
プロテクト メソッド Dispose  オーバーロードされます。 DataGridViewColumn によって使用されているすべてのリソースを解放します。 (DataGridViewColumn から継承されます。)
プロテクト メソッド Finalize  バンドに関連付けられたリソースを解放します。 (DataGridViewBand から継承されます。)
プロテクト メソッド MemberwiseClone  現在の Object の簡易コピーを作成します。 (Object から継承されます。)
プロテクト メソッド OnDataGridViewChanged  バンドが別の DataGridView に関連付けられている場合に呼び出されます。 (DataGridViewBand から継承されます。)
プロテクト メソッド RaiseCellClick  DataGridView.CellClick イベントを発生させます。 (DataGridViewElement から継承されます。)
プロテクト メソッド RaiseCellContentClick  DataGridView.CellContentClick イベントを発生させます。 (DataGridViewElement から継承されます。)
プロテクト メソッド RaiseCellContentDoubleClick  DataGridView.CellContentDoubleClick イベントを発生させます。 (DataGridViewElement から継承されます。)
プロテクト メソッド RaiseCellValueChanged  DataGridView.CellValueChanged イベントを発生させます。 (DataGridViewElement から継承されます。)
プロテクト メソッド RaiseDataError  DataGridView.DataError イベントを発生させます。 (DataGridViewElement から継承されます。)
プロテクト メソッド RaiseMouseWheel  Control.MouseWheel イベントを発生させます。 (DataGridViewElement から継承されます。)
パブリック イベントパブリック イベント
  名前 説明
パブリック イベント Disposed  DataGridViewColumn が破棄されたときに発生します。(DataGridViewColumn から継承されます。)
参照参照

関連項目

DataGridViewComboBoxColumn クラス
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.DataSource プロパティ
DataGridViewColumn.DataPropertyName プロパティ
DataSource
Items
ValueMember
DisplayMember
DataGridViewColumn クラス
DataGridViewRow
DataGridViewComboBoxCell クラス
DataGridViewComboBoxEditingControl
DataGridViewColumn.SortMode プロパティ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridViewComboBoxColumn」の関連用語

DataGridViewComboBoxColumnのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridViewComboBoxColumnのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS