0

コードビハインドがあり、これを実行すると例外がポップアップします。これを修正したい。それは私の心を食べてきました。どんな助けでも大歓迎です。

    private void StudentListView_DoubleClick(object sender, EventArgs e)
    {
        ListViewItem selectedListViewCell=StudentListView.SelectedItems[0];//
        //problem is about the line above. I have an argument out of range exception  here.
        //it says that InvalidArgument=Value of '0' is not valid for 'index'.
        selectedStudent = (Student)selectedListViewCell.Tag;
        SetDataInTextBoxes();

        selectedRowIndex=StudentListView.SelectedIndices[0];

        SaveButton.Visible = false;
        CancelButton.Visible = false;
        UpdateButton.Visible = false;
    }
4

1 に答える 1

1

これは、リスト ビューで選択されたアイテムがないことを意味します。最初にデザイナーでアイテムを選択したことを確認してください。そして、例外を避けるために、最初に確認してからこれを行う必要があります

ListViewItem selectedListViewCell;
if(StudentListView.SelectedItems.Count > 0)
     selectedListViewCell=StudentListView.SelectedItems[0];
于 2013-09-05T07:31:57.920 に答える