korrowan
korrowan

Reputation: 583

Datagridview row select values from record not showing

I have a datagridview that is populated by a combo box with 1 column. I need to be able to select that record and insert values not shown in the datagridview. Normally I would do this when I populate the all the values needed:

newlien.LienReason = (string)row.Cells["LienType"].Value;
newlien.LienNumber = (string)row.Cells["LienNumber"].Value;

Which will not work as the cells are not being populated. I am guessing that there are two solutions: either add the other columns and hide them and then pull the values from hidden cells or some way to get the values of the record without adding the values to the DGV. Either way I have no idea how to do it!

Upvotes: 0

Views: 539

Answers (1)

gnarlybracket
gnarlybracket

Reputation: 1720

The easiest way to do this is to add the desired column(s) to your DGV and then set visible to false in those DGV column properties. Then you can still pull values from the hidden columns, just like you would from any other column:

//hidden column
newlien.AnotherVariable = (string)row.Cells["HiddenColumn"].Value;

Let me know if this helps.

Upvotes: 2

Related Questions