custom datagrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Saso Zagoranski

    #1

    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 DataGridTextBox Column
    or DataGridBoolCol umn 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(Da taTable table)

    {

    this.DataBindin gs.Clear();

    this.TableStyle s.Clear();


    this.SetDataBin ding(table,"");


    DataGridTableSt yle ts1 = new DataGridTableSt yle();

    ts1.MappingName = "mainTable" ;

    // Set other properties.

    ts1.Alternating BackColor = Color.AliceBlue ;

    DataGridColumnS tyle[] textCol = new
    DataGridColumnS tyle[this.GridColumn s.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.GridColumn s.Length;i++ )

    {

    if ( ( this.ColumnType s == null ) || (this.ColumnTyp es.Length !=
    this.GridColumn s.Length) )

    {

    textCol[i] = new DataGridTextBox Column();

    }

    else

    {

    if ( this.ColumnType s[i] == ColumnType.Text Box )

    {

    textCol[i] = new DataGridTextBox Column();

    }

    else

    {

    textCol[i] = new DataGridBoolCol umn();

    }

    }


    textCol[i].MappingName = this.GridColumn s[i];


    if ( (this.HeaderTex t == null ) || (this.HeaderTex t.Length !=
    this.GridColumn s.Length) )

    {

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

    }

    else

    {

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

    }

    if ( ( this.ColumnSize s == null ) || (this.ColumnSiz es.Length !=
    this.GridColumn s.Length) )

    {

    textCol[i].Width = DEFAULT_WIDTH;

    }

    else

    {

    textCol[i].Width = this.ColumnSize s[i];

    }

    textCol[i].ReadOnly = true;

    }

    this.TableStyle s.Add(ts1);

    }


  • Saso Zagoranski

    #2
    Re: custom datagrid

    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" <saso.zagoransk i@guest.arnes.s i> wrote in message
    news:bnhf2p$8uo $1@planja.arnes .si...[color=blue]
    > Hi!
    >
    > I have extended the default windows.forms datagrid... I added a few[/color]
    options[color=blue]
    > if the data is bound programmaticly. .. The main part of the function (the
    > for loop) loops through all the columns and creates a[/color]
    DataGridTextBox Column[color=blue]
    > or DataGridBoolCol umn 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(Da taTable table)
    >
    > {
    >
    > this.DataBindin gs.Clear();
    >
    > this.TableStyle s.Clear();
    >
    >
    > this.SetDataBin ding(table,"");
    >
    >
    > DataGridTableSt yle ts1 = new DataGridTableSt yle();
    >
    > ts1.MappingName = "mainTable" ;
    >
    > // Set other properties.
    >
    > ts1.Alternating BackColor = Color.AliceBlue ;
    >
    > DataGridColumnS tyle[] textCol = new
    > DataGridColumnS tyle[this.GridColumn s.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.GridColumn s.Length;i++ )
    >
    > {
    >
    > if ( ( this.ColumnType s == null ) || (this.ColumnTyp es.Length !=
    > this.GridColumn s.Length) )
    >
    > {
    >
    > textCol[i] = new DataGridTextBox Column();
    >
    > }
    >
    > else
    >
    > {
    >
    > if ( this.ColumnType s[i] == ColumnType.Text Box )
    >
    > {
    >
    > textCol[i] = new DataGridTextBox Column();
    >
    > }
    >
    > else
    >
    > {
    >
    > textCol[i] = new DataGridBoolCol umn();
    >
    > }
    >
    > }
    >
    >
    > textCol[i].MappingName = this.GridColumn s[i];
    >
    >
    > if ( (this.HeaderTex t == null ) || (this.HeaderTex t.Length !=
    > this.GridColumn s.Length) )
    >
    > {
    >
    > textCol[i].HeaderText = this.GridColumn s[i];
    >
    > }
    >
    > else
    >
    > {
    >
    > textCol[i].HeaderText = this.HeaderText[i];
    >
    > }
    >
    > if ( ( this.ColumnSize s == null ) || (this.ColumnSiz es.Length !=
    > this.GridColumn s.Length) )
    >
    > {
    >
    > textCol[i].Width = DEFAULT_WIDTH;
    >
    > }
    >
    > else
    >
    > {
    >
    > textCol[i].Width = this.ColumnSize s[i];
    >
    > }
    >
    > textCol[i].ReadOnly = true;
    >
    > }
    >
    > this.TableStyle s.Add(ts1);
    >
    > }
    >
    >[/color]


    Comment

    Working...