How to use objects for a DataGridView

  • Thread starter Thread starter Sin Jeong-hun
  • Start date Start date
S

Sin Jeong-hun

Visual Studio .NET lets me to choose an object type (not an instance)
for the datasource of a datagridview control. Then it automatically
generates a ~~~bindingsource (~~~ is the object type name) component.
But I don't understand how to use it, I searched Google for this, but
couldn't find a tutorial or something. How can I actually set an
instance of a collection object for the datagridview? If there is a
tutorial page for this task, please direct me there. Thank you.
 
Visual Studio .NET lets me to choose an object type (not an instance)
for the datasource of a datagridview control. Then it automatically
generates a  ~~~bindingsource (~~~ is the object type name) component.
But I don't understand how to use it, I searched Google for this, but
couldn't find a tutorial or something. How can I actually set an
instance of a collection object for the datagridview? If there is a
tutorial page for this task, please direct me there. Thank you.

I found that the reason nothing came up on the control was that my
object has no properties but public fields. I created a property and
it was shown. I wonder if I have to make them all properties instead
of public fields, because that object has no operations and doesn't
need to validate the value of its public fields.
 
I wonder if I have to make them all properties instead
of public fields, because that object has no operations and doesn't
need to validate the value of its public fields.

The standard approach is, indeed, to use properties. Even if you don't
have validation.

With C# 3 you can make this as easy as fields using the new auto-
implemented property syntax:

public int Foo {get;set;}

I *strongly* recommend using properties. However, I have seen a
TypeDescriptionProvider implementation that exposed the fields via
runtime PropertyDescriptors, which allows binding to property-grids,
data-grid-view, etc. But I don't recommend it.

Marc
 
If you still can put you hand on it, this book has 2 nice chapters about
data source binding:

http://www.amazon.com/Windows-Forms...bs_sr_1?ie=UTF8&s=books&qid=1204574054&sr=1-1

It is a kind of 'historical progression' about data binding, but it may help
to understand the mechanic behind, which can be useful, on occasions.


Vanderghast, Access MVP



Visual Studio .NET lets me to choose an object type (not an instance)
for the datasource of a datagridview control. Then it automatically
generates a ~~~bindingsource (~~~ is the object type name) component.
But I don't understand how to use it, I searched Google for this, but
couldn't find a tutorial or something. How can I actually set an
instance of a collection object for the datagridview? If there is a
tutorial page for this task, please direct me there. Thank you.

I found that the reason nothing came up on the control was that my
object has no properties but public fields. I created a property and
it was shown. I wonder if I have to make them all properties instead
of public fields, because that object has no operations and doesn't
need to validate the value of its public fields.
 
Back
Top