Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, I'm having a problem with a program I am making, its a to do application, and on the main window there is a listview control, users are able to select an event and then edit it, trouble is, once I have changed the date and time deadline values, they do not go back to the main window, and there is no code I can find that will allow me to do this, here is the existing code for my edit button:

C#
private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (null != listTask.SelectedItems[0])
                {
                    EventForm EditEvent = new EventForm();
                    Event evt = TimerEvents[(Guid)listTask.SelectedItems[0].Tag];

                    EditEvent.taskName.Text = listTask.SelectedItems[0].Text;
                    EditEvent.timePicker.Value = evt.FireOn;
                    EditEvent.datePicker.Value = evt.FireOn;
                    EditEvent.notesBox.Text = listTask.SelectedItems[0].SubItems[3].Text;

                    if (DialogResult.OK == EditEvent.ShowDialog())
                    {
                        listTask.SelectedItems[0].Text = EditEvent.taskName.Text;
                        listTask.SelectedItems[0].SubItems[1] = EditEvent.timePicker.Value.ToString();
                        listTask.SelectedItems[0].SubItems[2] = EditEvent.datePicker.Value.ToString();
                        listTask.SelectedItems[0].SubItems[3].Text = EditEvent.notesBox.Text;
                    }
                }
            }
            catch
            {
                MessageBox.Show("No task selected, please select a task to edit first", "Ben's Task Manager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }


The bit where the timepicker and datepicker bits are used does not work, inside the if part, EditEvent.timePicker.Value.ToString throws an error like, could not implicitely convert type string to listview subitem, same for the datepicker, could anyone suggest a way in which this would work?

Thanks
Ben
Posted
Updated 8-Apr-12 14:12pm
v2

1 solution

C#
listTask.SelectedItems[0].SubItems[1] = EditEvent.timePicker.Value.ToString();
listTask.SelectedItems[0].SubItems[2] = EditEvent.datePicker.Value.ToString();


Perhaps?
C#
listTask.SelectedItems[0].SubItems[1].Text = EditEvent.timePicker.Value.ToString();
listTask.SelectedItems[0].SubItems[2].Text = EditEvent.datePicker.Value.ToString()
   
Comments
Member 14188342 5-May-19 12:16pm
   
lisTask = listview?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900