I have a ListView that displays multiple rows of ListViewItems. The user is able to edit the row by clicking the edit button which opens up another form displaying the selected row and the data within it. The problem I am having is that I cannot seem to update the ListViewItem on the parent form when I press the update button. The code I am using keeps throwing the exception message "An unhandled exception of type 'System.NullReferenceException' occurred in ToDoList.exe". I have tried different approaches to updating the selected item but cannot seem to get a working code.
This is the code I am using on the form that displays the selected row, button1 is the "Update Row" button that should update the listView.
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = (Form1)this.Owner;
int i = 0;
ListViewItem item = form1.listView1.SelectedItems[i];
textBox1.Text = item.SubItems[0].Text;
richTextBox1.Text = item.SubItems[1].Text;
comboBox1.Text = item.SubItems[2].Text;
dateTimePicker1.Text = item.SubItems[3].Text;
this.Close();
}
Aucun commentaire:
Enregistrer un commentaire