Reputation: 11
I have this gridview:
But need this:
I need to merge the columns for every road when they have the same value!!! I'm trying to make an Schedule with the gridview.
Thanks a lot for your help...
Upvotes: 0
Views: 1154
Reputation: 11
Here is the solution I made myself...
If any one else needs it...
for (int x = 0; x < e.Row.Cells.Count; x++)
{
// work out how wide the cell span should be for this cell
int span = 1;
while (
(x + span < e.Row.Cells.Count) &&
(e.Row.Cells[x + span].Text == e.Row.Cells[x].Text) &&
(e.Row.Cells[x].Text != " ")
)
{
span++;
}
// if we need to span this cell
if (span > 1)
{
// apply the span value to the first cell in the group
e.Row.Cells[x].ColumnSpan = span;
for (int n = 1; n < span; n++)
{
while (n < span)
{
e.Row.Cells[x + span - n].Visible = false;
n++;
}
}
// skip to the next cell past the end of the span
x += span - 1;
}
}
Upvotes: 1