custom datagrid

S

Saso Zagoranski

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 = new DataGridTextBoxColumn();

}

else

{

if ( this.ColumnTypes == ColumnType.TextBox )

{

textCol = new DataGridTextBoxColumn();

}

else

{

textCol = new DataGridBoolColumn();

}

}


textCol.MappingName = this.GridColumns;


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

{

textCol.HeaderText = this.GridColumns;

}

else

{

textCol.HeaderText = this.HeaderText;

}

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

{

textCol.Width = DEFAULT_WIDTH;

}

else

{

textCol.Width = this.ColumnSizes;

}

textCol.ReadOnly = true;

}

this.TableStyles.Add(ts1);

}
 
S

Saso Zagoranski

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... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top