gpt4 book ai didi

c# - 我如何修改我输入的记录?

转载 作者:搜寻专家 更新时间:2023-10-30 20:38:41 24 4
gpt4 key购买 nike

我正在使用 Windows 窗体创建待办事项列表。这是我到目前为止所拥有的。 enter image description here

这个表单的代码如下

namespace To_Do_List
{
public partial class To_Do_List : Form
{
public To_Do_List()
{
InitializeComponent();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e) //this is the exit button on the toolstrip
{
Application.Exit(); //exits the program when the Exit button is clicked in dropdown menu
}

private void button4_Click(object sender, EventArgs e)//This creates the button to open the about form
{
AboutMyProgram aboutForm = new AboutMyProgram();
aboutForm.ShowDialog(); //opens about form
}

private void button3_Click(object sender, EventArgs e) //This creates the button to open the form which ammends tasks
{
AmmendItem CreateForm = new AmmendItem(this);
CreateForm.Show();
}

private void button1_Click(object sender, EventArgs e) // This creates the button to open the form which creates new tasks
{
AddItem CreateForm = new AddItem(this);
CreateForm.Show();
}


public void listView1_SelectedIndexChanged_1(object sender, EventArgs e) // This creates the table
{


}

private void button2_Click(object sender, EventArgs e) //This Allows the user to delete entries
{
if (listView1.SelectedItems != null)
{
var confirmation = MessageBox.Show(
"Are you sure you want to delete this?",
"WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Question
);

if (confirmation == DialogResult.Yes)
{
for (int i = listView1.Items.Count - 1; i >= 0; i--)
{
if (listView1.Items[i].Selected)
{
listView1.Items[i].Remove();
i--;
}
}
}
}
}
}
}

要添加任务,表单如下所示 enter image description here

再次,代码如下

namespace To_Do_List
{
public partial class AddItem : Form
{

To_Do_List home;

public AddItem(To_Do_List parent)
{
InitializeComponent();
home = parent;
}

private void label1_Click(object sender, EventArgs e)
{

}

private void label1_Click_1(object sender, EventArgs e)
{

}

private void label2_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{

}

private void openListToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void sortByDateToolStripMenuItem_Click(object sender, EventArgs e)
{

}

public void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{

}

public void textBox1_TextChanged(object sender, EventArgs e)//Title Box
{

}

public void /*Description of Task*/richTextBox1_TextChanged(object sender, EventArgs e)
{

}

public void /*Priority Box*/comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close(); //causes the window to close but keeps the application running
}

private void aboutToDoListToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutMyProgram aboutForm = new AboutMyProgram();
aboutForm.ShowDialog(); //opens about form displaying copyright information
}

public void button1_Click(object sender, EventArgs e) //create task button
{
ListViewItem item1 = new ListViewItem(Title.Text);

item1.SubItems.Add(Description.Text);
item1.SubItems.Add(Priority.Text);
item1.SubItems.Add(Date.Text);
string value = "";
bool isChecked = Completed.Checked;
if (isChecked)
item1.SubItems.Add(Completed.Text);
else
value = null;

home.listView1.Items.Add(item1);

this.Close();


}

private void Date_ValueChanged(object sender, EventArgs e)
{

}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e) //Closes the window
{
this.Close();
}
}
}

修改表单与新任务表单完全相同。我将如何能够选择一条记录,按下修改按钮并实际更改?我很困惑。

此外,这实际上不是这个问题的一部分,但我会问它以防万一有人知道。我如何才能真正保存这些记录,以便在我再次打开应用程序时它们仍然存在?

非常感谢您的阅读,我知道我刚刚放弃了所有内容,但我对 Windows 窗体真的很陌生,所以我不想不小心错过一些重要的东西。

Edit

我做这样的事情是否走在正确的道路上?

 public void button1_Click(object sender, EventArgs e)
{
To_Do_List editform = new To_Do_List(Title.Text);
editform.Description.Text = listView1.SelectedItems[0].SubItems[0].Text;

仍然无法让它工作:/

最佳答案

弹出窗口的代码。

public partial class frmToDoDetails : Form
{
public string TaskTitle { get; set; }
public string Description { get; set; }
public bool EditMode { get; set; }

public frmToDoDetails()
{
InitializeComponent();
}

private void btnSave_Click(object sender, EventArgs e)
{
TaskTitle = txtTitle.Text;
Description = txtDesc.Text;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}

private void frmToDoDetails_Load(object sender, EventArgs e)
{
if (EditMode)
{
txtTitle.Text = TaskTitle;
txtDesc.Text = Description;
}
else {
txtTitle.Text = string.Empty;
txtDesc.Text = string.Empty;
}
txtTitle.Focus();
}
}

这是列表

public partial class frmToDo : Form
{
public frmToDo()
{
InitializeComponent();
}

private void btnNew_Click(object sender, EventArgs e)
{
frmToDoDetails frm = new frmToDoDetails();

if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] arr = new string[2];
ListViewItem itm;

arr[0] = frm.TaskTitle;
arr[1] = frm.Description;

itm = new ListViewItem(arr);
listView1.Items.Add(itm);
}

}

private void frmToDo_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;

//Add column header
listView1.Columns.Add("Title", 100);
listView1.Columns.Add("Desc", 70);

}

private void listView1_DoubleClick(object sender, EventArgs e)
{
ListViewItem currentItem= listView1.SelectedItems[0];
frmToDoDetails frm = new frmToDoDetails();
frm.TaskTitle = currentItem.SubItems[0].Text;
frm.Description = currentItem.SubItems[1].Text;
frm.EditMode = true;
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
currentItem.SubItems[0].Text=frm.TaskTitle;
currentItem.SubItems[1].Text=frm.Description;
}
}
}

我没有添加您的完整字段(优先级、日期等)。

希望对您有所帮助。

关于c# - 我如何修改我输入的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29958519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com