Peter Dzuya

Peter Dzuya

  • NA
  • 313
  • 40.8k

Getting Different Values

Jul 22 2015 5:38 PM
Hi Experts. I am still learning C#. I have two forms. The first one holds a list of Customers. The second one is supposed to edit what is listed in the first form. The User first highlights the customer he/she wants to edit from the customer grid listing form, then clicks the edit button which displays  items in the text boxes within the edit form.
 
The details shown from what is highlighted in the list is different from the edit form.
 
the code for editing in the listing form is as follows.
 
private void barButtonEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
 
try {
 
var customerEdit = CustomerListing.GetFocusedRow() as Customer;
 
if (customerEdit == null) return;
MessageBox.Show(Convert.ToString(customerEdit.Contact.ContactName));
 
var editCustomer = new frmEditCustomer(customerEdit.ContactId);
editCustomer.ShowDialog();
 
} catch (Exception Errhand) {
MessageBox.Show(Errhand.Message);
}
}
 
 and the code in my constructors within the Edit Customer form is as follows
 
private readonly ICustomerService _customerService;
private readonly Customer _customer;
private readonly IFinancialMonthService _financialMonthService;
private readonly FinancialYear _financialYear;
 
public frmEditCustomer() {
InitializeComponent();
 
_customerService = UnityConfig.GetContainer().Resolve<ICustomerService>();
_financialMonthService = UnityConfig.GetContainer().Resolve<IFinancialMonthService>();
_customer = new Customer() {
 
Active = true,
Accountclosed = false,
Datecreated = DateTime.Now,
LastEditedDate = DateTime.Now,
CompanyBranchId = CurrentUserInfo.User.CompanyBranch.CompanyId,
CheckerUserId = CurrentUserInfo.User.UserId,
LastEditorUserId = CurrentUserInfo.User.UserId
 
};
}
public frmEditCustomer(int customerId) :this(){
 
this._customer = _customerService.GetById(customerId);
 
MessageBox.Show(Convert.ToString(_customer.Contact.ContactName));
 
contactNameTextEdit.Text = _customer.Contact.ContactName;
remarksMemoEdit.Text = _customer.Remarks;
creditDaysCalcEdit.Text = Convert.ToString(_customer.CreditDays);
creditLimitCalcEdit.Text = Convert.ToString(_customer.CreditLimit);
}
 
the results from the two messageboxes bear different Customers.
 
So I wonder where I went wrong. Please help. Thanks. 

Answers (6)