从数据表尝试填充listview时,新手会出错

时间:2011-07-10 14:23:28

标签: c# listview datatable

我已经按照之前问题中的示例进行操作,并且在尝试从数据表填充listview控件时仍然出现错误。 这是我的代码

EvintoDataSet dsAppQualification = new EvintoDataSet();
EvintoDataSetTableAdapters.AppQualificationTableAdapter taAppQualification = 
     newEvintoDataSetTableAdapters.AppQualificationTableAdapter();

EvintoDataSet.AppQualificationDataTable dtAppQualification;
EvintoDataSet.AppQualificationRow drAppQualification;               
dtAppQualification = taAppQualification.GetAppQualification();
dsAppQualification.Tables.Add(dtAppQualification);


lvAppQualification.Items.Clear();


for (int i = 0; i < dtAppQualification.Rows.Count; i++)
{
    DataRow drow = dtAppQualification.Rows[i];

    // Only row that have not been deleted
    if (drow.RowState != DataRowState.Deleted)
    {
        // Define the list items
        ListViewItem lvi = new ListViewItem(drow["Queston"].ToString());
        // Add the list items to the ListView
        lvAppQualification.Items.Add(lvi);
    }
}

我收到了无效的参数错误 任何帮助是极大的赞赏。 安迪

1 个答案:

答案 0 :(得分:0)

由于您没有提供有关您所获得的错误的大量信息,例如发生错误的行,我只能假设导致错误的原因。我认为您需要在添加任何项目之前向列表视图添加列,可能就在'for'循环之前。