I have a Windows Form that has a Panel on it. A dynamically generated DataGridView control gets added to the Panel. One of the columns in the DGV is a combobox. It is populated with all possible Bottle Types when the DGV is created. Its initial value gets set to the value of one of the hidden columns. The form is called from a menu strip action. So it can be called over and over depending on what the user is doing.
The very first time the form is loaded, the combobox's value gets updated correctly. If I close the form and reopen it again, something is wrong and the combobox's values don't appear as updated.
Please see the attached document.
Of particular note, the very first time the form is loaded, the DGV CellEnter and CellLeave events don't fire unless you actually click into a column. But on subsequent form loads, both events fire even though I'm not entering or leaving any of the cells. I believe that might be a clue as to what's going on, but I can't prove or verify it. There is definitely something odd happening.
Without clouding the issue with all of my code, I will share the combobox column creation as well as the post-generating Value setting.
1. Inserting a combobox column. Based on a special object of type "AddOn" which is in addition to the columns retrieved from the SQL query:
Dim oCombo As New DataGridViewComboBoxColumn
oCombo.DataSource = oAddon.dgvCmbDatasource
oCombo.Width = oAddon.dgvWidth
oCombo.DisplayMember = "Display"
oCombo.ValueMember = "Value"
oDGV.Columns.Insert ( oAddon.dgvColumnNumber, oCombo )
oDGV.Columns( oAddon.dgvColumnNumber ).Name = oAddon.dgvColumnName ' "BottleType"
oDGV.Columns( oAddon.dgvColumnNumber ).HeaderText = oAddon.dgvHeaderText
oDGV.Columns( oAddon.dgvColumnNumber ).HeaderCell.Style.Alignment = oAddon.dgvHeaderAlignment
oDGV.Columns( oAddon.dgvColumnNumber ).Width = oAddon.dgvWidth
oDGV.Columns( oAddon.dgvColumnNumber ).ReadOnly = false
numCurrentWidth = oDGV.Size.Width
oDGV.Size = New Size ( numCurrentWidth + oAddon.dgvWidth, numHeight )
2. Populating the Value properety after creation:
For Each row As DataGridViewRow In objDGV.oDGV.Rows ' objDGV.oDGV
If Not row.IsNewRow Then
'
' Transfer the current bottle type ID to the combobox
'
' Sanity check: Get the current Bottle ID value
Dim strOld_ID As String = row.Cells ( "BottleType_ID" ).Value
' Change the Combobox value to match the current ID
row.Cells( "BottleType" ).Value = strOld_ID.ToString()
' Sanity check proof: Get the changed ID.
Dim strNew_ID As String = row.Cells ( "BottleType" ).Value
objDGV.oDGV.Refresh()
End if
Next
Hopefully someone has come across this type of problem and can shed some light.
Thanks in advance,
Jerry
Jerry Scannell
The very first time the form is loaded, the combobox's value gets updated correctly. If I close the form and reopen it again, something is wrong and the combobox's values don't appear as updated.
Please see the attached document.
Of particular note, the very first time the form is loaded, the DGV CellEnter and CellLeave events don't fire unless you actually click into a column. But on subsequent form loads, both events fire even though I'm not entering or leaving any of the cells. I believe that might be a clue as to what's going on, but I can't prove or verify it. There is definitely something odd happening.
Without clouding the issue with all of my code, I will share the combobox column creation as well as the post-generating Value setting.
1. Inserting a combobox column. Based on a special object of type "AddOn" which is in addition to the columns retrieved from the SQL query:
Dim oCombo As New DataGridViewComboBoxColumn
oCombo.DataSource = oAddon.dgvCmbDatasource
oCombo.Width = oAddon.dgvWidth
oCombo.DisplayMember = "Display"
oCombo.ValueMember = "Value"
oDGV.Columns.Insert ( oAddon.dgvColumnNumber, oCombo )
oDGV.Columns( oAddon.dgvColumnNumber ).Name = oAddon.dgvColumnName ' "BottleType"
oDGV.Columns( oAddon.dgvColumnNumber ).HeaderText = oAddon.dgvHeaderText
oDGV.Columns( oAddon.dgvColumnNumber ).HeaderCell.Style.Alignment = oAddon.dgvHeaderAlignment
oDGV.Columns( oAddon.dgvColumnNumber ).Width = oAddon.dgvWidth
oDGV.Columns( oAddon.dgvColumnNumber ).ReadOnly = false
numCurrentWidth = oDGV.Size.Width
oDGV.Size = New Size ( numCurrentWidth + oAddon.dgvWidth, numHeight )
2. Populating the Value properety after creation:
For Each row As DataGridViewRow In objDGV.oDGV.Rows ' objDGV.oDGV
If Not row.IsNewRow Then
'
' Transfer the current bottle type ID to the combobox
'
' Sanity check: Get the current Bottle ID value
Dim strOld_ID As String = row.Cells ( "BottleType_ID" ).Value
' Change the Combobox value to match the current ID
row.Cells( "BottleType" ).Value = strOld_ID.ToString()
' Sanity check proof: Get the changed ID.
Dim strNew_ID As String = row.Cells ( "BottleType" ).Value
objDGV.oDGV.Refresh()
End if
Next
Hopefully someone has come across this type of problem and can shed some light.
Thanks in advance,
Jerry
Jerry Scannell