How to bind Combobox in Windows applicaiton in Datagridview.

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

IN my VB.Net Windows application have two controls.

1.Datagridview

2.combobox


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
FillCombo()
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"
DataGridView1.Columns.Add(cmb)
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.Columns.Add(dcId)
dt.Columns.Add(dcName)
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


Responses

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

Up
0
Down
You will find an Answer here

http://stackoverflow.com/questions/11900502/adding-combobox-to-a-datagridview-for-a-particular-row

http://stackoverflow.com/questions/7448471/combobox-in-datagridview-in-edit-mode

Thank you for posting at Dotnetfunda
[Administrator]

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

Login to post response