How to create column in datagrid and bind to datasource?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to create column in datagrid and bind to datasource?

  1. #1
    Join Date
    Jan 2010
    Posts
    3

    Unhappy How to create column in datagrid and bind to datasource?

    Hi,
    Iam new in c# programming, i was able to define columns for datagrid in designer and binding the datagrid to datatable and then it displays successfully.

    but when trying to create the columns dynimcally and binding to the datatable iam getting an error


    "At least one of the DataGridView control's columns has no cell template"

    here is the code

    DataGridView dgList;

    DataGridViewColumn column1;

    column1=new DataGridViewColumn();
    column1.HeaderText="SN";
    column1.Width = 30;
    column1.Name = "SN";
    column1.DataPropertyName = "SN";

    dgList.Columns.Add(column1);

    dgList.DataSource=dataTable; // it stops here. DataTable already defined and filled

    what am i missing here ??
    please help

  2. #2
    Join Date
    Jan 2010
    Posts
    3

    Re: How to create column in datagrid and bind to datasource?

    i found the solution in case of somebody needs
    this line of code i came over it and not tried it of my idiocy

    DgDoc.AutoGenerateColumns = false ;
    i don't know what the relation between it and the error any way should be there.
    thanks for the read

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center