AutoGenerateColumns= false not working

Posted on 2006-03-30
Last Modified: 2008-01-09
I am able to set up my datagridview fine.  I use
DgvCalls.AutoGenerateColumns = false;
so that I can programmatically add columns.  The column that I added works fine, however the columns of the datasource are still coming up.  what am I doing wrong?  Below is my code.

//parent table

DaCustomers = new SqlDataAdapter("select * from Customers", conn);

DaCustomers.Fill(data, "Customers");

//child table

DaCalls = new SqlDataAdapter("select * from Calls", conn);

DaCalls.Fill(data, "Calls");

//table with look up values to use in datagridview later

DaTblLkUp = new SqlDataAdapter("select * from tblLkUP", conn);

DaTblLkUp.Fill(data, "tblLkUp");


DataRelation relation = new DataRelation(" CustomersCalls",





BindSourceCustomers.DataSource = data;

BindSourceCustomers.DataMember = "Customers";

//BindSource2 relation in tables

BindSourceCalls.DataSource = BindSourceCustomers;

BindSourceCalls.DataMember = "CustomersCalls";

//DataGridView shows the related values of the parent table

DgvCalls.DataSource = BindSourceCalls;

DgvCalls.AutoGenerateColumns = false;

//Set up Column with the look up value

One of the colums is called RsnCall.  The main table stores 1, 2, 3 ,4....the second table stores the values to the codes "get info", "appointment", ect

DataGridViewComboBoxColumn Col1 = new DataGridViewComboBoxColumn();

Col1.HeaderText = "Reason Call";

Col1.DataPropertyName = "RsnCall";

Col1.DataSource = data1;

Col1.DisplayMember = "tblLkUp.Name_Lk";

Col1.ValueMember = "tblLkUp.ID_Lk";

Col1.FlatStyle = FlatStyle.Flat;

DgvCalls.Columns.Insert(1, Col1);

What am I doing wrong????
Question by:yanci1179
    LVL 3

    Accepted Solution


    I tried your way and it's true, but try to invert your two lines:

    DgvCalls.AutoGenerateColumns = false;
    DgvCalls.DataSource = BindSourceCalls;

    Worked on mine!

    Author Comment

    thanks, switched the lines and it worked!!  Do you know why?  Thanks alot!!
    LVL 3

    Expert Comment

    Well, in .Net 2.0, it autibinds your DataSource, since the property is at true before then..

    Thanks for the points

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now