Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Rows' could not be initialized in web control...

Status
Not open for further replies.

koraykazgan

Programmer
Jan 11, 2005
17
DE
Hi there,

I am a C# programmer and want to create a Grid Web Control. I am about to finish the grid except rendering the control. I have a grid class, a row class and a cell class. The Grid contains the rows, and the rows the cells.

For the rows I have created a collection, inherited from CollectionBase. Also I created a collection for the cells in the same way. When I add items to the grid at design time I get the following error:

'Rows' could not be initialized.

I dont know why this happens. Here is the code of the grid control:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;

namespace Bilsa.BilsaControls
{
public class MegaCell
{
private string m_sText;
public string Text
{
get { return m_sText; }
set { m_sText = value; }
}
}

public class MegaCellCollection : CollectionBase
{
public MegaCell this[int index]
{
get { return ((MegaCell)(List[index])); }
set { List[index] = value; }
}

public int Add(MegaCell item)
{
return List.Add(item);
}

public void Insert(int index, MegaCell item)
{
List.Insert(index, item);
}
}


public class MegaRow
{
private MegaCellCollection m_Cells;

public MegaRow()
{
m_Cells = new MegaCellCollection();
}

[PersistenceMode(PersistenceMode.InnerProperty)]
public MegaCellCollection Cells
{
get { return m_Cells; }
set { m_Cells = value; }
}
}



public class MegaRowCollection : CollectionBase
{
public MegaRow this[int index]
{
get { return ((MegaRow)(List[index])); }
set { List[index] = value; }
}

public int Add(MegaRow item)
{
return List.Add(item);
}

public void Insert(int index, MegaRow item)
{
List.Insert(index, item);
}
}


public class RowEditor : System.ComponentModel.Design.CollectionEditor
{
public RowEditor(Type type) : base(type)
{
}
}

/// <summary>
/// Summary description for MegaGrid.
/// </summary>
[ToolboxData("<{0}:MegaGrid runat=server></{0}:MegaGrid>")]
public class MegaGrid : System.Web.UI.WebControls.WebControl
{
private MegaRowCollection m_Rows;

public MegaGrid()
{
m_Rows = new MegaRowCollection();
}

[Category("Bilsa Properties")]
[Editor(typeof(Bilsa.BilsaControls.RowEditor), typeof(System.Drawing.Design.UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public MegaRowCollection Rows
{
get { return m_Rows; }
//set { m_Rows = value; }
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write("Mega Grid Render");
}
}
}

Thanks for help,
Bye...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top