By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,771 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,771 IT Pros & Developers. It's quick & easy.

DataGridView bound to List<T>

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.