http://i.stack.imgur.com/DpO5L.jpg http://i.stack.imgur.com/S9XL4.jpg
如何从表格 1 中获取信息并将其添加到表格 2 中?
在表格 1 上,我有很多文本框、一些组合框和其他东西,我想将这些项目添加到表格 2 的列表框中。
这就是我所拥有的,但它不起作用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ClassofEmployees
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class employee
{ //will include the attributes of all employees of your organization.
//fields for employee
public int employeeId; // 5 digit number to represent employee
public int ssn; //social security number of employee
public string name; //employee name
public int dob; //date of birth
public int pay; //rate of pay
}
class managers : employee
{
public string backgroundCheck;
public string isSalary;
public string responsibilitys;
}
public void getEmployeeData(employee employee)
{
try
{
employee.employeeId = int.Parse(EmployeeID.Text);
employee.ssn = int.Parse(SSN.Text);
employee.name = employeeName.Text;
employee.dob = int.Parse(DOB.Text);
employee.pay = int.Parse(pay.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void BCToString()
{
string bcSelectedY;
string bcSelectedN;
if (bcselect.SelectedIndex != 1)
{
bcSelectedY = bcselect.SelectedItem.ToString();
}
else
{
bcSelectedN = bcselect.SelectedItem.ToString();
}
}
public void getMangerData(managers managers)
{
if (bcselect.SelectedIndex != 1)
{
managers.backgroundCheck = "yes";
}
else
{
managers.backgroundCheck = "no";
}
if (salary.SelectedIndex != 1)
{
managers.isSalary = "Yes";
}
else
{
managers.isSalary = "No";
}
managers.responsibilitys = responsibilitys.Text;
}
public void add_Click(object sender, EventArgs e)
{
//create new employee object
employee newemployee = new employee();
//get employee data
getEmployeeData(newemployee);
//create new manager object
managers newmanagerialemployee = new managers();
getMangerData(newmanagerialemployee);
EmployeeCumalitveList.employeeList.Items.Add(employee);
}
private void done_Click(object sender, EventArgs e)
{
EmployeeCumalitveList ecl = new EmployeeCumalitveList
ecl.Show;
this.Hide();
}
}
}
这是错误所在:
EmployeeCumalitveList.employeeList.Items.Add(employee);
我得到的错误是:
错误 1 类型 C:\Users\T-Ali\Desktop\SHawnasschool\vb.net 2 c#\projects\ClassofEmployees\ClassofEmployees\Form1.cs 108 66 ClassofEmployees 后的新表达式需要 ()、[] 或 {}
错误 2 可访问性不一致:参数类型“ClassofEmployees.Form1.employee”比方法“ClassofEmployees.Form1.getEmployeeData(ClassofEmployees.Form1.employee)”更难访问 C:\Users\T-Ali\Desktop\SHawnasschool\vb.net 2 c#\projects\ClassofEmployees\ClassofEmployees\Form1.cs 42 21 ClassofEmployees
错误 3 可访问性不一致:参数类型 'ClassofEmployees.Form1.managers' 比方法 'ClassofEmployees.Form1.getMangerData(ClassofEmployees.Form1.managers)' C:\Users\T-Ali\Desktop\SHawnasschool\vb.net 更难访问c#\projects\ClassofEmployees\ClassofEmployees\Form1.cs 70 21 ClassofEmployees