I am facing a problem in my VB.Net code.
I have an object factuurregel with the following properties:
Property Id As Integer
Property Medewerker As Medewerker
Property Datum As DateTime
Property Activiteit As Activiteit
Property Omschrijving As String
Property Tijd As Decimal
Property Tarief As Decimal
Property Specificatie As Boolean
Property Factureren As Boolean
Property NietFactureren As Boolean
Property Klant As FactKlant
Property Project As String
Another object I am using there is activiteit:
Property Id As Integer
Property Omschrijving As String
Property FactuurRegel As String
In a form, I have a datagrid, where I use following code:
Dim lActiviteiten As New List(Of Activiteit)
lActiviteiten = LoadActiveiten()
Dim dgAct As DataGridViewComboBoxColumn = DataGridUren.Columns(3)
dgAct.DataSource = lActiviteiten
AND
loadmwlist()
Dim dgMW As DataGridViewComboBoxColumn = DataGridUren.Columns(1)
With dgMW
.ValueMember = dtmw.Columns("ID").ToString
.DisplayMember = dtmw.Columns("Naam").ToString
.DataSource = dtmw.Copy
End With
where loadmwlist fills a table.
With both codes, the combobox in the datagrid is filled correct.
The problem is, when I set the object factuurregel as datasource, only in the medewerker combobox the right value is displayed. To be complete, the object medewerker is build like this:
Property Id As Integer
Property Naam As String
Why is the datasource correct when I use a table as datasource for the combobox, but not when I use a list of objects?
jmcilhinney said:
Why are you doing this: .ValueMember = dtmw.Columns("ID").ToString instead of this: .ValueMember = "ID"? Where are you setting the DisplayMember and ValueMember of dgAct? I'm not sure that you know what those properties actually do, so you probably ought to read up on them. –
after which I added
dgAct.DisplayMember = "Omschrijving"
dgAct.ValueMember = "Id"
Code is working as it should now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.