This is a migrated thread and some comments may be shown as answers.

The columns are appearing twice in the GridView after binding

2 Answers 443 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Arvind
Top achievements
Rank 1
Arvind asked on 15 May 2009, 06:44 AM
Hi,
   I have installed "RadControls_WinForms_2009_1_414_dev" and using the RadGridView control for our development.  I have created a RadGridView with three columns in the design time using the wizard (using "Open Propery Builder" link at the design time).  The names of the columns are ID, FullName and IsSelected.  The last IsSelected column is a check box column.  I have added the following code in the form load.

 

DataTable dt = new DataTable();

 

dt.Columns.Add(

"ID");

 

dt.Columns.Add(

"FullName");

 

dt.Columns.Add(

"IsSelected");

 

 

DataRow dr = dt.NewRow();

 

dr[

"ID"] = "1";

 

dr[

"FullName"] = "Arvind";

 

dr[

"IsSelected"] = true;

 

dt.Rows.Add(dr);

 

dr = dt.NewRow();

dr[

"ID"] = "2";

 

dr[

"FullName"] = "Robin";

 

dr[

"IsSelected"] = true;

 

dt.Rows.Add(dr);

 

dr = dt.NewRow();

dr[

"ID"] = "3";

 

dr[

"FullName"] = "Kumar";

 

dr[

"IsSelected"] = false;

 

dt.Rows.Add(dr);

radGvw.DataSource = dt;

While running the application, totally 6 columns are generated.  All the three columns are repeated.  The columns are displaying in the order ID, FullName, IsSelected, ID, FullName, IsSelected.  The IsSelected column type is textbox column in the second time.

I am new to this Telerik control.  Please advice.

Regards,
Arvind Robin Kumar.

2 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 15 May 2009, 07:34 AM
Hello Arvind,

Thanks for writing.

I am happy that you have chosen to develop your UI with RadControls for WinForms.

When binding RadGridView its default behavior is to automatically generate the columns based on the object that you are using as a datasource. In your case there are two approaches that you can take in order to prevent your grid from displaying 6 columns instead of 3:

1. You can set the RadGridView.MasterGridViewTemplate.AutoGenerateColumns property to false before binding the grid to your DataTable. Please note that this property is only visible from the code, you will not see it in the Property Grid for the RadGridView control in the Visual Studio Designer. Here is a code snippet that demonstrates how to use the property:

this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false

or

2. You can remove the columns that you created at design-time and without setting the property mentioned above to false, just bind your grid to your data table. The columns will be generated automatically.

I hope this will be helpful.

Do not hesitate to write back if you need further assistance.

Kind regards,
Deyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Arvind
Top achievements
Rank 1
answered on 15 May 2009, 08:20 AM
Hi,

Thank you.  Now it is working fine.

Regards,
Arvind Robin Kumar.
Tags
GridView
Asked by
Arvind
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Arvind
Top achievements
Rank 1
Share this question
or