471,075 Members | 706 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

custom datagrid

Hi!

I have extended the default windows.forms datagrid... I added a few options
if the data is bound programmaticly... The main part of the function (the
for loop) loops through all the columns and creates a DataGridTextBoxColumn
or DataGridBoolColumn for each of them...
The problem is, that the DataGrid always displays just one of the columns!
I have tried binding the DataTable after adding the TableStyle but that
didn't work... I have also tried
using the AddRange method and adding all of the columns at once but that
doesn't work either...
I really don't know what I'm doing wrong...

Any help?
Saso

Here is the code:

public void InitDataGrid(DataTable table)

{

this.DataBindings.Clear();

this.TableStyles.Clear();
this.SetDataBinding(table,"");
DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName = "mainTable";

// Set other properties.

ts1.AlternatingBackColor = Color.AliceBlue;

DataGridColumnStyle[] textCol = new
DataGridColumnStyle[this.GridColumns.Length];

/* Add a GridColumnStyle and set its MappingName

to the name of a DataColumn in the DataTable.

Set the HeaderText and Width properties. */

for ( int i = 0;i < this.GridColumns.Length;i++ )

{

if ( ( this.ColumnTypes == null ) || (this.ColumnTypes.Length !=
this.GridColumns.Length) )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

if ( this.ColumnTypes[i] == ColumnType.TextBox )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

textCol[i] = new DataGridBoolColumn();

}

}
textCol[i].MappingName = this.GridColumns[i];
if ( (this.HeaderText == null ) || (this.HeaderText.Length !=
this.GridColumns.Length) )

{

textCol[i].HeaderText = this.GridColumns[i];

}

else

{

textCol[i].HeaderText = this.HeaderText[i];

}

if ( ( this.ColumnSizes == null ) || (this.ColumnSizes.Length !=
this.GridColumns.Length) )

{

textCol[i].Width = DEFAULT_WIDTH;

}

else

{

textCol[i].Width = this.ColumnSizes[i];

}

textCol[i].ReadOnly = true;

}

this.TableStyles.Add(ts1);

}
Nov 15 '05 #1
1 1469
Never mind :) I'm not even going to tell you what I did wrong :) Stupid
mistake, has nothing to do with the class I wrote... It works fine... :)

"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:bn**********@planja.arnes.si...
Hi!

I have extended the default windows.forms datagrid... I added a few options if the data is bound programmaticly... The main part of the function (the
for loop) loops through all the columns and creates a DataGridTextBoxColumn or DataGridBoolColumn for each of them...
The problem is, that the DataGrid always displays just one of the columns!
I have tried binding the DataTable after adding the TableStyle but that
didn't work... I have also tried
using the AddRange method and adding all of the columns at once but that
doesn't work either...
I really don't know what I'm doing wrong...

Any help?
Saso

Here is the code:

public void InitDataGrid(DataTable table)

{

this.DataBindings.Clear();

this.TableStyles.Clear();
this.SetDataBinding(table,"");
DataGridTableStyle ts1 = new DataGridTableStyle();

ts1.MappingName = "mainTable";

// Set other properties.

ts1.AlternatingBackColor = Color.AliceBlue;

DataGridColumnStyle[] textCol = new
DataGridColumnStyle[this.GridColumns.Length];

/* Add a GridColumnStyle and set its MappingName

to the name of a DataColumn in the DataTable.

Set the HeaderText and Width properties. */

for ( int i = 0;i < this.GridColumns.Length;i++ )

{

if ( ( this.ColumnTypes == null ) || (this.ColumnTypes.Length !=
this.GridColumns.Length) )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

if ( this.ColumnTypes[i] == ColumnType.TextBox )

{

textCol[i] = new DataGridTextBoxColumn();

}

else

{

textCol[i] = new DataGridBoolColumn();

}

}
textCol[i].MappingName = this.GridColumns[i];
if ( (this.HeaderText == null ) || (this.HeaderText.Length !=
this.GridColumns.Length) )

{

textCol[i].HeaderText = this.GridColumns[i];

}

else

{

textCol[i].HeaderText = this.HeaderText[i];

}

if ( ( this.ColumnSizes == null ) || (this.ColumnSizes.Length !=
this.GridColumns.Length) )

{

textCol[i].Width = DEFAULT_WIDTH;

}

else

{

textCol[i].Width = this.ColumnSizes[i];

}

textCol[i].ReadOnly = true;

}

this.TableStyles.Add(ts1);

}

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Vagabond Software | last post: by
7 posts views Thread by Girish | last post: by
1 post views Thread by Sam Samnah | last post: by
1 post views Thread by rn5a | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.