Wednesday, 11 February 2015

ComboBox in Datagridview

How to fill ComboBox in Datagridview in vb.net

I have added a combo box in a specific column in the grid and i have populated it. So when the grid is filled the combo box are also filled with predefined values.

1. Write the code at .vb page

  Dim sql As String

        sql = "select * from color_mas"
        Dim dt As DataTable
        dt = DataTable(sql)
     
        If dt.Rows.Count > 0 Then

            'For j As Integer = 0 To dt.Rows.Count - 1

            Dim col As New DataGridViewComboBoxColumn
            col.DataPropertyName = "Color Name"
            col.HeaderText = "Colorname"
            col.Name = "Colorid"

            col.DataSource = dt
            col.DisplayMember = "Colorname"
            col.ValueMember = "Colorid"
            DataGridView1.Columns.Insert(0, col)

        End If

2. After Add control add filled look like this



No comments:

Post a Comment

Working with 3- Tier Architecture in C#

  Introduction In this article we will learn Use to 3- Tier architecture in C#.NET application. 3-Tier architecture is very famous and ...