You must Sign In to post a response.
  • Category: .NET

    Add combobox in gridview

    How to add comobox in gridview in vb.net source code
  • #768697
    The DataGridView control is use for displaying tabular data with Windows Forms. You can use this code snippet to add combobox in gridview in vb.net source code
     Imports System.Data.SqlClient
    Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    DataGridView1.ColumnCount = 3
    DataGridView1.Columns(0).Name = "Product ID"
    DataGridView1.Columns(1).Name = "Product Name"

    Dim row As String() = New String() {"1", "Product 1"}
    DataGridView1.Rows.Add(row)
    row = New String() {"2", "Product 2"}
    DataGridView1.Rows.Add(row)
    End Sub
    End Class

  • #768698
    simply you can create a rows and add it in gridview, see below snippet

    private void button1_Click(object sender, EventArgs e)
    {
    dataGridView1.ColumnCount = 3;
    dataGridView1.Columns[0].Name = "Product ID";
    dataGridView1.Columns[1].Name = "Product Name";
    dataGridView1.Columns[2].Name = "Product Price";

    string[] row = new string[] { "1", "Product 1", "1000" };
    dataGridView1.Rows.Add(row);
    row = new string[] { "2", "Product 2", "2000" };
    dataGridView1.Rows.Add(row);
    row = new string[] { "3", "Product 3", "3000" };
    dataGridView1.Rows.Add(row);
    row = new string[] { "4", "Product 4", "4000" };
    dataGridView1.Rows.Add(row);

    DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
    cmb.HeaderText = "Select Data";
    cmb.Name = "cmb";
    cmb.MaxDropDownItems = 4;
    cmb.Items.Add("True");
    cmb.Items.Add("False");
    dataGridView1.Columns.Add(cmb);

    }


    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments