467,867 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,867 developers. It's quick & easy.

DataGridView bound to List<T>

Hi,

I am trying to bind a DataGridView to a generic List<T>. I've set up the
columns in the designer, then used this code:

dgv.DataSource = MyList;
dgv.Columns[0].DataPropertyName = "Property1"
dgv.Columns[1].DataPropertyName = "Property2"
dgv.Columns[2].DataPropertyName = "Property3"

Where "Property1", etc are public properties of object T.

When I run the form, the datagrid view shows all the values twice. First,
it displays all the columns I set up at design time (with the correct values
for each row), then it creates new columns for each of object T's public
properties.

What is it I'm not doing right?
Apr 4 '06 #1
  • viewed: 24133
Share:
2 Replies
Nathan wrote:
Hi,

I am trying to bind a DataGridView to a generic List<T>. I've set up the
columns in the designer, then used this code:

dgv.DataSource = MyList;
dgv.Columns[0].DataPropertyName = "Property1"
dgv.Columns[1].DataPropertyName = "Property2"
dgv.Columns[2].DataPropertyName = "Property3"

Where "Property1", etc are public properties of object T.

When I run the form, the datagrid view shows all the values twice. First,
it displays all the columns I set up at design time (with the correct values
for each row), then it creates new columns for each of object T's public
properties.

What is it I'm not doing right?


Do you have AutoGenerateColumns turned on?

Chris
Apr 4 '06 #2
Aaah, thanks. Turned AutoGenerateColumns off; now it works. New it had to
be something simple.

"Chris" wrote:
Nathan wrote:
Hi,

I am trying to bind a DataGridView to a generic List<T>. I've set up the
columns in the designer, then used this code:

dgv.DataSource = MyList;
dgv.Columns[0].DataPropertyName = "Property1"
dgv.Columns[1].DataPropertyName = "Property2"
dgv.Columns[2].DataPropertyName = "Property3"

Where "Property1", etc are public properties of object T.

When I run the form, the datagrid view shows all the values twice. First,
it displays all the columns I set up at design time (with the correct values
for each row), then it creates new columns for each of object T's public
properties.

What is it I'm not doing right?


Do you have AutoGenerateColumns turned on?

Chris

Apr 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Dave | last post: by
2 posts views Thread by Brian Pelton | last post: by
reply views Thread by Iron Moped | last post: by
7 posts views Thread by Andrew Robinson | last post: by
35 posts views Thread by Lee Crabtree | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.