COMBOBOX DALAM DATAGRID

Untuk membuat combobox dalam datagridview cukup dengan menambahkan datagridview ke dalam form kemudian buatlah coding di bawah ini :

combo

 

coding :


Imports System.Data.SqlClient

 

Public Class combodalamgrid

Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet

 

Sub konekdb()
conn = New SqlConnection("data source=.\sqlexpress;initial catalog=dbnashir;integrated security=true") 'tidak menggunakan password
conn.Open()
End Sub

 

Private Sub combodalamgrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call konekdb()
da = New SqlDataAdapter("Select Nama_barang from tblbarang", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds)

Dim cols As New DataGridViewComboBoxColumn
cols.DataSource = ds.Tables(0)
cols.DisplayMember = "Nama_barang"
DataGridView1.Columns.Add(cols)
cols.HeaderText = "Nama Barang"
cols.Width = 300
End Sub
End Class