Click here to Skip to main content
15,306,032 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello,

I have populated a combobox in a datagridview. This works perfect. My issue is, how do i assign a certain value to the combobox in a datagridview? I want the user to be able to load the form and have a certain value already displayed with the option to choose items that have been added to the combobox.
VB
For Each row In Me.DataGridView1.Rows
           row.Height = 40
           row.DefaultCellStyle.WrapMode = DataGridViewTriState.True
           Dim dgvcombo As DataGridViewComboBoxCell
           dgvcombo = row.Cells(2)
           row.Cells(0).Value = tasknum
           row.Cells(1).Value = GetScalarData("SELECT duedate FROM task WHERE capaID = '" & CAPAid & "' AND task = '" & tasknum & "'")
           For i = 0 To x.Count - 1
               dgvcombo.Items.Add(x(i))
           Next


           tasknum = tasknum + 1
       Next row


Any help would be greatly appreciated.

Thank You
Posted

Have a look here: DataGridViewComboBoxColumn Class[^]
On the bottom of related page, you'll find an example how to bind data to DataGridViewComboBoxColumn.
   
VB
dgvcombo.Value = dgvcombo.Items(0)

will select the first of your items

A DataGridViewComboBoxCell uses .Value
not .Text like a normal ComboBox
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900