download gratis video tutorial vb 6 dan vb.net plus contoh aplikasi

cara-membuat-combobox-dalam-datagridview-vbnet

 


combo

 

coding :


Imports System.Data.SqlClient

 

Public Class combodalamgrid

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

 

Sub konekdb()

'tidak menggunakan password
conn = New SqlConnection("data source=.\sqlexpress;initial catalog=MyDB;integrated security=true")
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