I have been working on keeping things object oriented for my project. Currently, I'm using a .DLL which supplies all of the app's classes to the WinForms project acting as the presentation layer.
My .DLL will, for example, return a SortableBindingList(Of T) to code in a form. The SortableBindingList(Of T) comes from here. Let's assume a SortableBindingList(Of Product). Assuming that the .DLL's function Services.Products.GetList()
returns a SortableBindingList(Of Product), I can easily do this:
DataGridView1.DataSource = Services.Products.GetList()
Now, the DataGridView is properly populated with my list of Products. Fine. However, there is no .SelectedItem property which gives me back my object which was selected in the DataGridView:
' Doesn't exist!
Dim p As Product = DataGridView1.SelectedItem
' Need to make another DB call by getting the Product ID
' from the proper Cell of the DataGridView ... yuck!
However, a ComboBox or a ListBox does in fact store and return my Product objects intact:
' Valid!
ComboBox1.DataSource = Services.Products.GetList()
Dim p as Product = ComboBox1.SelectedItem
Another however ... the ComboBox and ListBox do not show all of the fields of the Product object, only the value of the DisplayMember property.
Is there a nice control in VB.NET 2008 that I am just missing, which gives me the object oriented functionality that I want which will actually display an entire object's fields and also return that object back when selected by the user? I'm at a loss as to why there wouldn't be.