M
Michael C
I wish to show a collection of objects in the DataGridView control. This is
working fairly well except in one particular case. If my collection starts
empty when I assign it to the grid then when an item is added, the item
appears but every cell in the grid is blank. I am assigning the collection
to the grid like this:
MyGrid.DataSource = MyCollection
This works great if the collection contains 1 or more items but in the case
that the user is creating a new collection from scratch then it does not
work. I can see what is happening, the grid doesn't know which columns to
bind to which properties of my object if the collection has not objects. So
far I've managed to get around this by rebinding my collection to the grid
when the first item is added but this seems like a hack. Anyone have a
better solution?
BTW, I create the columns in the grid at design time and have set
AutoGenerateColumns to false.
Thanks,
Michael
working fairly well except in one particular case. If my collection starts
empty when I assign it to the grid then when an item is added, the item
appears but every cell in the grid is blank. I am assigning the collection
to the grid like this:
MyGrid.DataSource = MyCollection
This works great if the collection contains 1 or more items but in the case
that the user is creating a new collection from scratch then it does not
work. I can see what is happening, the grid doesn't know which columns to
bind to which properties of my object if the collection has not objects. So
far I've managed to get around this by rebinding my collection to the grid
when the first item is added but this seems like a hack. Anyone have a
better solution?
BTW, I create the columns in the grid at design time and have set
AutoGenerateColumns to false.
Thanks,
Michael