Specified Cast Is Not Valid

  • Thread starter Thread starter James Goodman
  • Start date Start date
J

James Goodman

I am attempting to use a bound combo box in a datagrid & am getting the above error.

The code which sets the properties for my combo column is:
Friend WithEvents DataGridComboBoxColumn1 As DataGridTextBoxCombo.DataGridComboBoxColumn

Me.DataGridComboBoxColumn1 = New Proj.DataGridTextBoxCombo.DataGridComboBoxColumn()

Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn3, Me.DataGridComboBoxColumn1})

Me.DataGridTableStyle1.MappingName = "DataTableName"

'
'DataGridComboBoxColumn1
'
Me.DataGridComboBoxColumn1.Format = ""
Me.DataGridComboBoxColumn1.FormatInfo = Nothing
Me.DataGridComboBoxColumn1.HeaderText = "Column Header"
Me.DataGridComboBoxColumn1.MappingName = "DataTableColumn"
Me.DataGridComboBoxColumn1.Width = 115
Me.DataGridComboBoxColumn1.ColumnComboBox.DataSource = Me.DataSourceName.Tables("LookupTableName")
Me.DataGridComboBoxColumn1.ColumnComboBox.DisplayMember = "LookupTableName.DescriptionColumn"

Me.DataGridComboBoxColumn1.ColumnComboBox.ValueMember = "LookupTableName.OBJECTID"


N.B.
The grid worked before I added this combo-box column.
I remembered to fill the dataset when the form loads.


Any suggestions as to what I can do to find/fix this?


--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 
Have found the solution to this problem:

Me.DataGridComboBoxColumn1.ColumnComboBox.DataSource = Me.DataSourceName.Tables("LookupTableName")

Needed to be:
Me.DataGridComboBoxColumn1.ColumnComboBox.DataSource = Me.DataSourceName.Tables("LookupTableName").DefaultView

It then worked perfectly...

--
Cheers,


James Goodman MCSE, MCDBA
http://www.angelfire.com/sports/f1pictures
 
Back
Top