I have a datagridview bound to a bindingsource. Two of the columns contain values that link to the primary keys in other tables. Instead of displaying the primary key values, I would like to display the name of the item associated with the primary key. In other words, the primary key value may be 3 but I want to display “Furnace 5” in the datagridview instead of 3 (which it is now displaying).
I have a datagridview bound to a bindingsource. Two of the columns contain values
Share
There are at least four ways of doing this (from easiest to hardest)
1) Linq to DataSet
This assumes a typed DataSet with two DataTables Products and ProductTypes. This isn’t required (they don’t have to be in the same dataset and the ProductType doesn’t have to be DataTable)
using linq to dataset requires .NET 3.5 and up
2) Retrieve the data the way you need it and bind to the desired column
3) Don’t use a TextBoxColumn and use a ComboBoxDataColumn instead.
4) Create a custom DataGridViewColumn that does the lookup.