我的DataGridView上只显示最后一行

时间:2012-05-16 19:19:45

标签: c# winforms datagridview

以下代码是我每次要向tableDocTypes DataGridView添加行时调用的方法。调试显示RowCount正在递增并且所有传递的数据都是正确的,但是一旦表单显示它只显示最后一行。显示的最后一行也是应该是空格的行,因此我无法添加任何新行,因为星号旁边没有空白单元格。我的猜测是我不应该使用tableDocTypes.RowCount - 1作为索引,但它似乎正在递增,我找不到任何其他可用的东西。任何信息都有帮助。

private void addRowToDocTypeTable(bool docTypeValid, string formName, string formCabinet, string docType)
{
    tableDocTypes.Rows.Add();

    if (!docTypeValid)
    {
        // Change color to yellow and display IndexWarning icons
        tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnDocTypeImage.Index].Value = Properties.Resources.IndexWarning;
        tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnDocType.Index].Style.BackColor = Color.LightGoldenrodYellow;
    }
    else
    {
        // Index is good so display IndexCorrect and leave line white
        tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnDocTypeImage.Index].Value = Properties.Resources.IndexCorrect;
    }

    tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnFormName.Index].Value = formName;
    tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnFormCabinet.Index].Value = formCabinet;
    tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnDocType.Index].Value = docType;

    // Assign the rename menue to only the image column
    tableDocTypes.Rows[tableDocTypes.RowCount - 1].Cells[columnDocTypeImage.Index].ContextMenuStrip = menuDocTypeEdit;
}

0 个答案:

没有答案