Is it possible to use a primitive-typed Collection, such as List<long>, as the DataSource for a DataGridView?
After a half-hearted attempt to make it work, I gave in and created a simple struct so I could give DataGridViewColumn a PropertyName. But now I have to box my values when I deal with the UI, unbox them for the rest of my app (thus negating the benefits of data binding), and implement IComparable and IEquatable in my struct to support List sorting and searching (a simple enough task, the existence of the struct itself is cluttersome enough).
It seems like a while lot of overhead and clutter just to give a list of values to a UI widget. Surely there is an easier way…
If you have a list of numbers that you want to show to the user consider using a
ComboBox. This way you can set theDataSourceto theList<long>.However, if you really need the
DataGridViewyou can change yourList<long>toList<Long?>and you can now bind a grid view column to theValueproperty of the bounded list. This approach saves you the custom struct, but it’s still a compromise solution.