PROBLEMA COM DATAGRIDVIEW

DNEVONY 09/05/2011 12:23:29
#373507
galera bom dia, estou tendo um problema com as linhas do meu datagridview no c# com dados vindo de uma tabela do mysql quando chega na última linha do datagridview ele me diz que nao existe o índice estou tentando fazer o que se segue abaixo e nao estou conseguindo, nas linhas anteriores ele funciona normalmente mas na última não por favor me ajudem

protected void GridDadosEmpenhos_RowDataBound(object sender, GridViewRowEventArgs e)
{
#region [Ô]Deixa invisível a coluna[Ô]
switch (e.Row.RowType)
{
case DataControlRowType.Header:
e.Row.Cells[5].Visible = false;
break;
case DataControlRowType.DataRow:
e.Row.Cells[5].Visible = false;
break;
case DataControlRowType.Footer:
e.Row.Cells[5].Visible = false;
break;
}
#endregion
//int TotalLinhas = Convert.ToInt32(Session[[Ô]totallinhas[Ô]].ToString());
if (e.Row.RowType == DataControlRowType.DataRow)
{

//We[ô]re only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = ((DataRowView)e.Row.DataItem);


if (previousCat == drv[[Ô]anopagamento[Ô]].ToString())
{

//If it[ô]s the same category as the previous one
//Increment the rowspan
if (GridDadosEmpenhos.Rows[firstRow].Cells[5].RowSpan == 0)
{
GridDadosEmpenhos.Rows[firstRow].Cells[5].RowSpan = 2;

}
else
{
GridDadosEmpenhos.Rows[firstRow].Cells[5].RowSpan += 1;

//Remove the cell
e.Row.Cells.RemoveAt(5);
if (firstRow > 1)
{
GridDadosEmpenhos.Rows[firstRow - 1].Cells[3].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[2].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[1].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[0].Text = [Ô]Total Pago[Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[4].ForeColor = Color.DarkBlue;
GridDadosEmpenhos.Rows[firstRow - 1].Cells[0].ForeColor = Color.DarkBlue;
GridDadosEmpenhos.Rows[firstRow - 1].Cells[0].Font.Bold = true;
GridDadosEmpenhos.Rows[firstRow - 1].Cells[4].Font.Bold = true;
}
}

}

else //It[ô]s a new category
{

//Set the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;

//Maintain the category in memory
previousCat = drv[[Ô]anopagamento[Ô]].ToString();

firstRow = e.Row.RowIndex;
if (firstRow > 1)
{
GridDadosEmpenhos.Rows[firstRow - 1].Cells[3].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[2].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[1].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[0].Text = [Ô]Total Pago[Ô];
GridDadosEmpenhos.Rows[firstRow - 1].Cells[4].ForeColor = Color.DarkBlue;
GridDadosEmpenhos.Rows[firstRow - 1].Cells[0].ForeColor = Color.DarkBlue;
GridDadosEmpenhos.Rows[firstRow - 1].Cells[0].Font.Bold = true;
GridDadosEmpenhos.Rows[firstRow - 1].Cells[4].Font.Bold = true;
if (totallinhas == GridDadosEmpenhos.Rows.Count)
{
string teste = Convert.ToString(e.Row.FindControl([Ô][Ô]));
if (teste == [Ô][Ô])
{
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[3].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[2].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[1].Text = [Ô][Ô];
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[0].Text = [Ô]Total Geral Pago[Ô];
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[4].ForeColor = Color.DarkRed;
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[0].ForeColor = Color.DarkRed;
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[0].Font.Bold = true;
GridDadosEmpenhos.Rows[e.Row.RowIndex].Cells[4].Font.Bold = true;
}
}
}

}

}
}
TECLA 12/06/2011 10:41:40
#376556
Já tentou fazer o Debug e acompanhar a execução do RowDataBound e identificar a linha que gera a Exception?
RICART 12/06/2011 14:07:25
#376565
Vc tem que considerar o total de linhas da sua tabela -1, pois o daatagridview inicia no índice 0. Não deu para ver onde vc trata a variável TotalLinhas. Parece que ainda falta uma parte do código.
Tópico encerrado , respostas não são mais permitidas