ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Windows Form DataGridView ComboBoxColumn does not open DropDown on Click<p>I will get back soon.</p>, 30 Apr 2019 04:28:26 GMTWindows Form DataGridView ComboBoxColumn does not open DropDown on Click<p>Hi <a class="username" rel="PSowmiya"> PSowmiya</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">private void Form1_Load(object sender, EventArgs e) { dataGridView1.DataSource = GetData(&#34;SELECT CustomerId, Name FROM Customers&#34;); DataGridViewComboBoxColumn checkBoxColumn = new DataGridViewComboBoxColumn(); checkBoxColumn.HeaderText = &#34;&#34;; checkBoxColumn.Width = 70; checkBoxColumn.Name = &#34;ComboBoxColumn&#34;; dataGridView1.Columns.Insert(0, checkBoxColumn); } private void dgv_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex &gt; -1) { DataGridViewComboBoxCell dgvComboBoxCell = new DataGridViewComboBoxCell(); if (dataGridView1.Columns[e.ColumnIndex].Name.Contains(&#34;ComboBoxColumn&#34;)) { dataGridView1[e.ColumnIndex, e.RowIndex] = dgvComboBoxCell; dgvComboBoxCell.DataSource = GetData(&#34;SELECT CustomerId , Country FROM Customers&#34;); dgvComboBoxCell.ValueMember = &#34;CustomerId&#34;; dgvComboBoxCell.DisplayMember = &#34;Country&#34;; } } } private DataTable GetData(string query) { using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.CommandType = CommandType.Text; using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { using (DataTable dt = new DataTable()) { sda.Fill(dt); return dt; } } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load dataGridView1.DataSource = GetData(&#34;SELECT CustomerId, Name FROM Customers&#34;) Dim checkBoxColumn As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn() checkBoxColumn.HeaderText = &#34;&#34; checkBoxColumn.Width = 70 checkBoxColumn.Name = &#34;ComboBoxColumn&#34; dataGridView1.Columns.Insert(0, checkBoxColumn) End Sub Private Sub dgv_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dataGridView1.CellClick If e.ColumnIndex &gt; -1 Then Dim dgvComboBoxCell As DataGridViewComboBoxCell = New DataGridViewComboBoxCell() If dataGridView1.Columns(e.ColumnIndex).Name.Contains(&#34;ComboBoxColumn&#34;) Then dataGridView1(e.ColumnIndex, e.RowIndex) = dgvComboBoxCell dgvComboBoxCell.DataSource = GetData(&#34;SELECT CustomerId , Country FROM Customers&#34;) dgvComboBoxCell.ValueMember = &#34;CustomerId&#34; dgvComboBoxCell.DisplayMember = &#34;Country&#34; End If End If End Sub Private Function GetData(ByVal query As String) As DataTable Using con As SqlConnection = New SqlConnection(ConnectionString) Using cmd As SqlCommand = New SqlCommand(query, con) cmd.CommandType = CommandType.Text Using sda As SqlDataAdapter = New SqlDataAdapter(cmd) Using dt As DataTable = New DataTable() sda.Fill(dt) Return dt End Using End Using End Using End Using End Function</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="" alt="" width="370" height="196" /></p>, 30 Apr 2019 06:13:18 GMT