c# c# 从零到精通 form界面之listView控件
using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test04
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == “”)
{
MessageBox.Show(“项目不能为空”);
}
else
{
listView1.Items.Add(textBox1.Text.Trim());
textBox1.Text = “”;
}
}
private void button3_Click(object sender, EventArgs e)
{
if (listView1.Items.Count == 0)
{
MessageBox.Show(“项目中已经没有项目”);
}
else
{
listView1.Items.Clear();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0)
{
MessageBox.Show(“请选择要删除的项”);
}
else
{
listView1.Items.RemoveAt(listView1.SelectedItems[0].Index);
listView1.SelectedItems.Clear();
}
}
}
}文章来源地址https://www.toymoban.com/news/detail-482433.html
文章来源:https://www.toymoban.com/news/detail-482433.html
到了这里,关于c# 从零到精通 form界面之listView控件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!