Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi GUys I have a DataGridView bound to a Retrurn DataSet Table From a Database.

One of the columns is an integer which represents a Text Value.

i.e. 40 = HardenSteel

So im my research I thought I would use a DataGridViewComboBoxColumn and attach a table of data with the Integer and corresponding Text Value so that the user can see the text value but it uses the integer value.

Here is the Code that has gets the data and it returns information as expected.
VB
Dim X As clsDataBaseToolsX = New clsDataBaseToolsX()
RetDat(Counter) = X.GetDatabaseDataset("SELECT '[INDEX]', '[NAME]' FROM STEEL").Tables(0)



Then in the loader is:

VB
Dim CBoxCol As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
CBoxCol.HeaderText = mColumnHeadings(Index)
CBoxCol.DataPropertyName = mColumnHeadingsDB(Index)
CBoxCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox
CBoxCol.DataSource = mColumnExtendEdData(Index)
CBoxCol.ValueMember = mColumnExtendEdData(Index).Columns(0).ToString
CBoxCol.DisplayMember = mColumnExtendEdData(Index).Columns(1).ToString
mDataGrdView.Columns.Add(CBoxCol)





But I always get an error message about

System.FormatException DataGridViewComboBoxCell Value is not Valid.

Can anyone tell what I am doing wrong or at best tell me how to trap for this?

Stephan
Posted

1 solution

OK Answer I found by myself.....Woooohooooo

I was putting Long's as the Value Member and the data in the dataviewgrid was and integer... hence the type value error.

But I would still love to know if anyone has a way of trapping this error as I only get a dialog with this error.

I thank you all in advance, and thanks for your patience.

Stephan
 
Share this answer
 

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