We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

AutoGenerateColumns= false not working

yanci1179
yanci1179 asked
on
Medium Priority
1,206 Views
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.

Thanks.
//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");

//relation

DataRelation relation = new DataRelation(" CustomersCalls",

data.Tables["Customers"].Columns["IDCall"],

data.Tables["Calls"].Columns["IDCall"],false);

data.Relations.Add(relation);

//BindSource1

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????
Comment
Watch Question

Commented:
Well,

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

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

Worked on mine!

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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

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

Thanks for the points
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.