views:

248

answers:

1

What's the best practise way to handle a primary key in an unbound datagrid view combo-box column?

I want to display a meaningful value but store only the primary key (much like Access combo-boxes). I achieve this with a regular combo-box by adding an object with two properties into the items collection rather than a plain string. I then retrieve this by casting the selected index value of the combo-box back into it's object form and then retrieving the properties. This works very well but I am unable to replicate the technique with a datagridview combo as I can't seem to access the items collection. I only seem to be able to retrieve a string value back from the grid although I can add the object as normal when creating the column.

Hope this makes sense...

+1  A: 

RESOLVED - Set the combo datasource to a collection class and use the ValueMember and DisplayMember properties in the same way as when binding to a datasource. Works a treat.

Simon