0

I am displaying a list of a specific object (Bag) on a DataGridView. This object, contains other objects, for example, an object Book.

What I've done:

BagList = List(Of Bag)

After filling the list:

DataGridView1.DataSource = BagList

So on the book attribute of the DataGridView, I find that on the column "Book", is populated with the classname (BOOK), but I would like to display its id attrbute.

Is there any way to make the datagridview to show an attribute of the object BOOK and not trying to show the object itself on that field?

Cristian
  • 199
  • 2
  • 13
  • 1
    override the `.ToString` of Book https://www.dotnetperls.com/tostring-vbnet – Slai Sep 19 '16 at 02:30
  • If you can't modify the definition of the `Book` class as suggested then you would either have to create a custom column type for the grid or use an unbound column. – jmcilhinney Sep 19 '16 at 02:34
  • Overriding the .ToString function on the Book class to return the attribute I wanted did the trick: `Public Overrides Function ToString() As String` `Return _id` `End Function` – Cristian Sep 19 '16 at 02:43
  • You may find more options in this post. [How to bind a column from second level list on bindsource in winforms datagridview](http://stackoverflow.com/questions/36469904/how-to-bind-a-column-from-second-level-list-on-bindsource-in-winforms-datagridvi) – Reza Aghaei Sep 21 '16 at 00:36

0 Answers0