嗨,我是 C# 的新手,我没有编程背景,但我对此很感兴趣。
我想将数据发送到 ListView,但数据是另一种形式。我已经在这里看到了所有相关的帖子。我尝试从其中一篇文章中复制代码并根据我的需要进行更改,但它不起作用。
表格3:
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public delegate void HandleItemAdded(object sender, ItemAddedEventArgs e);
public struct ItemAddedEventArgs: EventArgs
{
public string PartPrefix;
public string PartStartNumber;
public string AssemblyPrefix;
public string AssemblyStartNumber;
public string Name;
public string Profile;
public string Material;
public string Finish;
public string Class;
public ItemAddedEventArgs(string partprefix, string partstartnumber, string assemblyprefix, string assemblystartnumber, string name, string profile, string material, string finish, string classes)
{
PartPrefix = partprefix;
PartStartNumber = partstartnumber;
AssemblyPrefix = assemblyprefix;
AssemblyStartNumber = assemblystartnumber;
Name = name;
Profile = profile;
Material = material;
Finish = finish;
Class = classes;
}
}
public event HandleItemAdded ItemAdded;
public void RaiseItemAdded(ItemAddedEventArgs e)
{
if (ItemAdded != null)
ItemAdded(this, e);
}
public void AddToList()
{
RaiseItemAdded (new ItemAddedEventArgs (textBox221.Text, textBox222.Text, textBox223.Text, textBox224.Text, textBox225.Text, textBox226.Text, textBox227.Text, textBox228.Text, textBox229.Text));
}
}
表格1:
public void HandleItemAdded(object sender, WindowsFormsApplication1.Form3.ItemAddedEventArgs e)
{
ListViewItem item1 = new ListViewItem(textBox221.Text);
item1.SubItems.Add(textBox222.Text);
item1.SubItems.Add(textBox223.Text);
item1.SubItems.Add(textBox224.Text);
item1.SubItems.Add(textBox225.Text);
item1.SubItems.Add(textBox226.Text);
item1.SubItems.Add(textBox227.Text);
item1.SubItems.Add(textBox228.Text);
item1.SubItems.Add(textBox229.Text);
listView1.Add(item1);
Form3.ItemAdded += Form1.HandleItemAdded; *<-( i dont know if this is the correct place for this.)
}
我得到的错误是:type EventArgs in interface list is not an interface
先感谢您。