Binding a DataGridView

G

Guest

Hi,
I'm using a List(of T) as the DataSource for a DataGridView. The list is a
list of objects for which I wrote the class. The headers in the DataGridView
are the names of the properties of the class, and the DataGridView columns
appear in some apparent random order (if not random, I can't figure out what
the order is).

My questions are:
1) how do I control the order of the columns in the DGV (preferably from my
class, or the List(of T) )
2) can I code something in my class to control the DGV headers ( I know I
can use brute force to set the column headers after creating the DGV, but I'd
like to know if I can override the DGV's default behavior by coding something
in my class)

Thanks,
Tom
 
G

Guest

Tom,

I'm not 100% sure if this would work, but you could try implementing the
ITypedList interface in your DataSource class. This gives you control over
which properties will be bound to the grid. The DataView class implements
this interface. If you don't implement it directly, the framework uses
reflection to query your public properties as you already know.
 
G

Guest

That looks like it might work Pete. Thanks for the tip. I'll post a reply
here if I can make it work.

Best,
Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top