header column span problems

M

Mortar

i am trying to span header columns and am getting some problems. I
have 13 columns in my datagrid (1 template, 12 bound), and for some
reason, when i try to remove cells of index 11 or higher, it says the
index is not a valid index. Basically, I want the last 6 header
columns to span. Below is the code:

private void dgResults_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Header)
{
DataGridItem dgItem;
TableCellCollection tcells;
TableCell fcell;
TableCell scell;
dgItem = e.Item;
tcells = e.Item.Cells;
fcell = e.Item.Cells[0];
fcell.Text = "";
fcell = e.Item.Cells[1];
fcell.Text = "";
fcell = e.Item.Cells[2];
fcell.Text = "";
fcell = e.Item.Cells[3];
fcell.Text = "";
fcell = e.Item.Cells[4];
fcell.Text = "";
fcell = e.Item.Cells[5];
fcell.Text = "";
fcell = e.Item.Cells[6];
fcell.Text = "";
fcell = e.Item.Cells[7];
fcell.Text = "My Question goes here";
fcell.ColumnSpan = 6;
fcell.BackColor = System.Drawing.Color.Black;
scell = e.Item.Cells[8];
dgItem.Cells.Remove(scell);
scell = e.Item.Cells[9];
dgItem.Cells.Remove(scell);
scell = e.Item.Cells[10];
dgItem.Cells.Remove(scell);
scell = e.Item.Cells[11];
dgItem.Cells.Remove(scell);
scell = e.Item.Cells[12];
dgItem.Cells.Remove(scell);
}

}

it bombs out on the scell = e.Item.Cells[11]; line

Any ideas why?
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top