新手在尝试从datatable填充listview时出现错误

本文关键字:listview 错误 填充 datatable 新手 | 更新日期: 2023-09-27 18:01:45

我遵循了前面问题中的示例,并且在尝试从数据表填充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);
    }
}

我得到一个无效参数错误非常感谢任何帮助。安迪

新手在尝试从datatable填充listview时出现错误

由于您没有给出关于所得到的错误的太多信息,例如发生错误的行,因此我只能假设导致错误的原因。我认为你需要在添加任何项目之前添加列到你的listview,可能在'for'循环之前。