Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表视图列标题索引返回-1_C#_Listview - Fatal编程技术网

C# 列表视图列标题索引返回-1

C# 列表视图列标题索引返回-1,c#,listview,C#,Listview,我有一个列表视图,我声明了如下列标题 private System.Windows.Forms.ColumnHeader Debtorname; private System.Windows.Forms.ColumnHeader Message; private System.Windows.Forms.ColumnHeader Hpno; private System.Windows.Forms.ColumnHeader Status; private

我有一个列表视图,我声明了如下列标题

    private System.Windows.Forms.ColumnHeader Debtorname;
    private System.Windows.Forms.ColumnHeader Message;
    private System.Windows.Forms.ColumnHeader Hpno;
    private System.Windows.Forms.ColumnHeader Status;
    private System.Windows.Forms.ColumnHeader Timestamp;
    private System.Windows.Forms.ColumnHeader sentBY;
    private System.Windows.Forms.ColumnHeader submitTime;
    private System.Windows.Forms.ColumnHeader debtorid;
    private System.Windows.Forms.ColumnHeader Account;

    private System.Windows.Forms.ColumnHeader Client;
    private System.Windows.Forms.ColumnHeader Batchno;
 ListViewItem lvi = new ListViewItem(new string[lstSMSReport.Columns.Count]);
 lvi.SubItems[Debtorname.Index].Text = myReader["debtorName"].ToString();
 lvi.SubItems[Status.Index].Text = myReader["status"].ToString();

 lvi.SubItems[Timestamp.Index].Text = myReader["timestamp"].ToString();
我填充listviewitems,如下所示

    private System.Windows.Forms.ColumnHeader Debtorname;
    private System.Windows.Forms.ColumnHeader Message;
    private System.Windows.Forms.ColumnHeader Hpno;
    private System.Windows.Forms.ColumnHeader Status;
    private System.Windows.Forms.ColumnHeader Timestamp;
    private System.Windows.Forms.ColumnHeader sentBY;
    private System.Windows.Forms.ColumnHeader submitTime;
    private System.Windows.Forms.ColumnHeader debtorid;
    private System.Windows.Forms.ColumnHeader Account;

    private System.Windows.Forms.ColumnHeader Client;
    private System.Windows.Forms.ColumnHeader Batchno;
 ListViewItem lvi = new ListViewItem(new string[lstSMSReport.Columns.Count]);
 lvi.SubItems[Debtorname.Index].Text = myReader["debtorName"].ToString();
 lvi.SubItems[Status.Index].Text = myReader["status"].ToString();

 lvi.SubItems[Timestamp.Index].Text = myReader["timestamp"].ToString();
当我运行上面的程序时,我得到了我期望的结果,但是下面的两个ColumnHeader抛出了异常

  lvi.SubItems[Client.Index].Text = myReader["clientname"].ToString();
  lvi.SubItems[Batchno.Index].Text = myReader["batchno"].ToString();
当我把两个放进去时,试着接住。然后我意识到a-1作为两列的索引返回。我花了几个小时想弄明白为什么,但还是弄不明白


如果您有任何建议,我们将不胜感激。

myReader、clientname、batchno中的结果在myReader中可用??是的。我甚至将它们传递给字符串变量进行测试。谢谢,但我发现了错误。原来我的前任为我不知道的项目设置了一个条件。谢谢大家。