将数据从一种形式传输到listView [英] transfer data from one form to listView

查看:58
本文介绍了将数据从一种形式传输到listView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个程序,该程序正在做一个应用程序,并且在主窗口上有一个listview控件,用户可以选择一个事件,然后对其进行编辑,麻烦是,一旦我更改了日期和时间期限值,它们将不会返回主窗口,并且没有代码可以使我执行此操作,这是我的编辑按钮的现有代码:

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:

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);
            }
        }



使用timepicker和datepicker位的位不起作用,在if部分中,EditEvent.timePicker.Value.ToString引发错误,例如,无法隐式将类型字符串转换为listview子项,与datepicker相同,有人可以建议这将如何工作?

谢谢
Ben



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

推荐答案

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



也许吗?



Perhaps?

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


这篇关于将数据从一种形式传输到listView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆