DataGridViewComboBoxColumn problems when manually creating view

G

Guest

When using a datagridview, which contains one DataGridViewComboBoxColumn, I
get an error (System.FormatException: DataGridViewComboBoxCell value is not
valid), which has something to do with the databinding.

Situation:
I create a tabledef:
Dim dt As DataTable
dt = New DataTable(TABELDISPLAY)
dt.Columns.Add("CostplanID", GetType(Long))
dt.Columns.Add("CosttypeID", GetType(Long))
gDatasetDisplay.Tables.Add(dt)

I fill it:
For Each MyRow As DataRow In gdbProject.Costplan.GetRows()
dr = gDatasetDisplay.Tables(TABELDISPLAY).NewRow()
dr("CostplanID") = gdbProject.Costplan.CostplanID(MyRow)
dr("CosttypeID") = gdbProject.Costplan.GetCosttypeID(CostplanID)
gDatasetDisplay.Tables(TABELDISPLAY).Rows.Add(dr)
Next
MyDataView = New DataView(gDatasetDisplay.Tables(TABELDISPLAY), "", "",
DataViewRowState.CurrentRows) '"[MilestoneID]=" & MilestoneID & " AND
[PartnerID]=" & PartnerID
MyDataGridView.DataSource = MyDataView

I add a combo to the list, which should be linked to CosttypeID
Dim List As New DataGridViewComboBoxColumn()
List.HeaderText = "Costtype"
List.DataPropertyName = "CosttypeID"
DBProgram.Costtype.GetCosttypes(List)
.Columns.Add(List)

This however does not seem to work. What am I doing wrong???

The odd thing however, If I use the following code (which I do not WANT to
use), it shows the combobox without the error!:

gDatasetDisplay = New DataSet
Dim MyDBLink As New DBLink(DBProgram.GetConnectionString, QUERYDISPLAY,
TABELDISPLAY)
MyDBLink.OpenRecordset(gDatasetDisplay)
MyDBLink.Dispose()
MyDataView = New DataView(gDatasetDisplay.Tables(TABELDISPLAY), "", "",
DataViewRowState.CurrentRows) '"[MilestoneID]=" & MilestoneID & " AND
[PartnerID]=" & PartnerID
MyDataGridView.DataSource = MyDataView
 
G

Guest

Just some more info:

If I disable the error warning, and run the program, I get a datagridview
with in the combobox the values of the costtypeID. When I press the dropdown,
it shows me the names of the costtypes. If I unbind the column, it shows the
costtypes all the time (but this is not what I need).

The combobox datasource is:
Public Function GetCosttypes(ByRef MyCombobox As
DataGridViewComboBoxColumn) As Boolean
MyCombobox.DisplayMember = "Costtype"
MyCombobox.ValueMember = "CosttypeID"
MyCombobox.DataSource = GetDataView()
Return True
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top