Bound Datagridview and combobox

oohrah

New member
Joined
Oct 28, 2010
Messages
1
Programming Experience
3-5
I have a bound datagridview and need some comboboxes. I have scoured the net for the last few days and have tried about a dozen different things but nothing as of yet that resolves my issue. As I have said the datagridview is bound at runtime to a dataset. I also have the tables with the needed info for the comboboxes preloaded also. At runtime the datagridview is all textboxes. Here is the code so far dealing with this area. Any guidance and/or help is greatly appriciated. Help me save what little hair I have left :confused:

VB.NET:
                Dim col As New DataGridViewTextBoxColumn
                Dim colCompanies As New DataGridViewComboBoxColumn

                dgvViewResultsCerts.DataSource = Nothing
                QueryCertificates(cSQL)
                dgvViewResultsCerts.DataSource = modGlobals.SCA_DATA.Tables("CERTIFICATESDATA")

                dgvViewResultsCerts.Columns(0).Visible = False
                dgvViewResultsCerts.Columns(0).HeaderText = "CID"

                dgvViewResultsCerts.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                col = dgvViewResultsCerts.Columns(1)
                col.MaxInputLength = 100
                dgvViewResultsCerts.Columns(1).HeaderText = "C-Number"

                colCompanies.DataPropertyName = "COMPANYID"
                colCompanies.DataSource = modGlobals.SCA_DATA.Tables("tblCompanies")
                colCompanies.DisplayMember = "CUID"
                colCompanies.ValueMember = "NAME"
                colCompanies.HeaderText = "Company"
                colCompanies = dgvViewResultsCerts.Columns(2)
 
col = dgvViewResultsCerts.Columns(1)
'...
colCompanies = dgvViewResultsCerts.Columns(2)
Here you are assigning existing columns from dgv to the col/colCompanies variables, when I think you are trying to do the opposite, ie adding your custom columns to dgv. This is done using the Add method of the Columns collection:
VB.NET:
dgv.Columns.Add(yourcolumn)
You also have to set the columns DataPropertyName to map the bound data to this column.
I will actually suggest you add and configure the customized columns in the designer, if they are not conditional. Likewise, using the Data Sources wizards is usually easier than writing code, when this is an option.
 
Back
Top