我有一个列表视图,我在下面声明了列标题。
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;
我填写下面的listviewitems。
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();
当我运行上述内容时,我得到了我期待的结果,但是下面的两个列标题都抛出了异常。
lvi.SubItems[Client.Index].Text = myReader["clientname"].ToString();
lvi.SubItems[Batchno.Index].Text = myReader["batchno"].ToString();
当我把这两个试试并抓住时。然后我意识到-1返回作为两列的索引。我花了几个小时试图找出原因,但仍然不能。
请提出任何建议。