How to bind Combobox in Windows applicaiton in Datagridview.

Posted by Jayakumars under ASP.NET on 2/21/2013 | Points: 10 | Views : 3703 | Status : [Member] [MVP] | Replies : 1

IN my VB.Net Windows application have two controls.



Datagridview have only one colum ie combobox column

If i select the data in combobox means the corresponding selected value relate data will load in datagridview combobox

How will do this windows application?

My Code Like this
Dim dt1 As New DataTable
Dim cmb As New DataGridViewComboBoxColumn()

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub FillCombo()
cmb.HeaderText = "Select Data"
cmb.Name = "cmb"
cmb.MaxDropDownItems = 4
dt1 = Dttables()
cmb.DataSource = dt1
cmb.ValueMember = "EmpId"
cmb.DisplayMember = "EmpName"
CmbEmpId.DataSource = dt1
CmbEmpId.ValueMember = "EmpId"
CmbEmpId.DisplayMember = "EmpName"
End Sub

Private Function Dttables() As DataTable
Dim dt = New DataTable()
Dim dcId = New DataColumn("EmpId", GetType(Integer))
Dim dcName = New DataColumn("EmpName", GetType(String))
dt.Rows.Add("1", "JehovahJireh")
dt.Rows.Add("2", "Jayakumar")
dt.Rows.Add("3", "Joseph")
dt.Rows.Add("4", "David")
dt.Rows.Add("5", "Abraham")
dt.Rows.Add("6", "Isac")
Return dt
End Function

Private Sub CmbEmpId_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles CmbEmpId.SelectedIndexChanged
'How to bind Cmb -> Combox selected Value
cmb.SelectedValue = 1
cmb.ValueMember = "0"
End Sub

I try this CmbEmpId_SelectedIndexChanged event
i canot do selected value so any one solve this

check my image below

Mark as Answer if its helpful to you
EmailId :


Posted by: Vuyiswamb on: 2/22/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

You will find an Answer here

Thank you for posting at Dotnetfunda

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response