如何将数据从bindingsource传递给对象

时间:2016-04-28 09:01:19

标签: c# winforms

我有一个winform表单,它使用bindingsource作为自定义对象的数据源。如何将bindingsource中的数据分配给我的对象。这样我就可以将该对象作为函数C#

中的参数传递
     class Employee: EntityBase
     {
          public string EmployeeID
          { 
            get { return _EmployeeID; }
            set
            {
               if (Equals(value, _EmployeeID)) return;
              _EmployeeID = value;
              NotifyPropertyChanged(() => EmployeeID);
           }
     }

我的保存按钮看起来像这样

      private void RbBtSave_ItemClick(object sender, ItemClickEventArgs e)
      {
        HRConstant URI = new HRConstant();
        var client = new HttpClient { BaseAddress = new   Uri(URI.ClientHtt()) };
        HREmployeeTrans HREmployeeTrans = new HREmployeeTrans();
        //this.hREmployeeBindingSource.AddNew();
        Employee VarEmployee = new Employee();
        VarEmployee = (Employee)EmployeeBindingSource.AddNew();
        //MessageBox.Show(VarEmployee.EmployeeID);
        HREmployeeTrans.CreateEmployees(client, VarHREmployee);
      }

1 个答案:

答案 0 :(得分:0)

我能够通过在表单load事件中创建一个对象实例并使用该对象初始化bindingsource来解决问题

HREmployee VarHREmployee= new HREmployee();
EmployeeBindingSource.datasource=VarHREmployee;