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);
}