Frustrating problem with DatGridView

G

Guest

I have a DatagridView bound to a bindingsource. I programmatically add a
ComboboxColumn and bind it to another BindingSource like this:

Dim colActType As New DataGridViewComboBoxColumn
colActType.DataSource = ActivityTypesBindingSource
colActType.HeaderText = "Activity Type"
colActType.DataPropertyName = "ActivityTypeId"
colActType.ValueMember = "Id"
colActType.DisplayMember = "Descr"
DataGridView1.Columns.Add(colActType)

The values behave as expected. The displayed values in the Combobox
correctly display the value from the Descr field. Changing the value saves
correctly to the main table. The problem is that when the DataGridView
displays, the Combobox column displays the value in the ValueMember field.
When I click in the combobox, it shows the DisplayMember value, but reverts
back when I click or tab away.

Any thoughts would be helpful.

Barry

PS: Apologies if this message posts twice. I'm not sure why that is
happening here.
 
G

Guest

Resolved!

For posterity, here's what was going on:
The data types of the Value Member and the DataPropertyName fields did not
match. One was a Byte and the other an Integer. This caused a formatting
exception when populating the DataGridView. I couyldn't find a solution to
this originally, so I trapped it and let it die. The unfortunate side-effect
was that the Value Member value was being displayed in the column instead of
the Display Member value.

All is well, oh my children, and it only cost me two days and a lot of
heartache.

Barry
 

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

Top