【发布时间】:2016-12-05 17:00:24
【问题描述】:
我需要一些帮助。我正在使用 C# 开发具有 2 个 ListView、2 个按钮和 4 个 TextBox 的应用程序。第一个按钮是将 textbox1 和 textbox2 中的文本添加到 listview1 作为项目及其子项目。它还在listview2中添加了它。按钮 2 应该在 listview2 中添加更多子项(来自 textbox3 和 textbox4),但我不知道该怎么做。这是我的 button1 代码:
private void button1_Click(object sender, EventArgs e)
{
string s1, s2;
s1 = textBox1.Text;
s2 = textBox2.Text;
if(textBox1.Text!="" && textBox2.Text!="")
{
string[] items = { s1, s2 };
ListViewItem row = new ListViewItem(items);
listView1.Items.Add(row);
string[] items2 = { s1, s2 };
ListViewItem row2 = new ListViewItem(items2);
listView2.Items.Add(row2);
textBox1.Text = textBox2.Text = "";
}
else
{
MessageBox.Show("Enter all data!", "Error");
}
}
private void button2_Click(object sender, EventArgs e)
{
//I need code here.
}
问题是:如何在已经用button1添加的子项之后用button2在listview2中添加更多子项? (我已经创建了所有需要的列。)
【问题讨论】:
-
我猜,上面的代码是有效的。您为什么不在按钮 2 中尝试相同的操作?
-
我只需要在每一行中添加更多子项。你刚才说的那是行不通的。
标签: c# listview listviewitem