DataGridView avoiding adding new columns

Posted by phenevo on Stack Overflow See other posts from Stack Overflow or by phenevo
Published on 2010-03-15T10:36:48Z Indexed on 2010/03/15 10:39 UTC
Read the original article Hit count: 181

Filed under:
|

Why, this code create 2 the same columns in grid (Color and Color). How to inputs data color from collection in column which existing before set datasource ??

public Form1()
        {
            InitializeComponent();
            DataGridViewTextBoxColumn ds = new DataGridViewTextBoxColumn();
            ds.Name = "Color";
            dataGridView1.Columns.Add(ds);

            List<Car>  cars=new List<Car>();
            for (int i = 0; i < 5; i++)
            {
                Car car=new Car {Type = "type" + i.ToString(),Color=Color.Silver};
                cars.Add(car);

            }
            dataGridView1.DataSource = cars;


        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about datagridview