Hi,
I have a data grid view which includes a combo box column. The combo box column is the second column in the grid view. I have a button which fills the grid based on some conditions entered in a text box. The combo box is bound to a dataset and then the grid is bound to another dataset. This works fine the first time I click the button. However when I click the button the second time I get this error
Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxColumn' to type 'System.Windows.Forms.DataGridViewComboBoxColumn'."
Could anyone let me know why this happens
The code behind the button is shown below
Private
Sub btnAssignGetPackage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssignGetPackage.Click
Try
Dim ds As DataSet = DB.GetPackagesUnionConfig(Me.cboEnviron.SelectedValue, Me.txtAssignFilter.Text)
Dim dsAreas As DataSet = DB.GetAreas(Me.cboEnviron.SelectedValue)
If ds.Tables(0).Rows.Count > 0 Then
Me.dgv_AssignSelectPackage.Visible = True
Me.btnAssignSavePackage.Visible = True
Dim lst As DataGridViewComboBoxColumn = CType(dgv_AssignSelectPackage.Columns(1), DataGridViewComboBoxColumn)
lst.DataSource = Nothing
lst.DataSource = dsAreas.Tables(0)
lst.DisplayMember = "AREA"
lst.ValueMember = "AREA"
Me.dgv_AssignSelectPackage.DataSource = Nothing
Me.dgv_AssignSelectPackage.DataSource = ds
Me.dgv_AssignSelectPackage.DataMember = ds.Tables(0).TableName
Else
Me.dgv_AssignSelectPackage.Visible = False
Me.btnAssignSavePackage.Visible = False
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error when retreiving Packages")
End Try
End Sub
Thanks in advance
Cooper