DataBindings, BindingContext's, CurrencyManagers etc...
-
Just curious. I have a master form with a DataGridView on it showing me the records of a DataTable. The same form also holds 3 buttons. (An "Insert", "Update" and "Delete" button). Clicking "Insert" I do : CustomerForm Form = new CustomerForm(m_CustomerDT.NewCustomerRow()); : if (Form.ShowDialog() == DialogResult.OK) m_CustomerDT.AddCustomerRow(Form.CustomerRow); Clicking "Update" I do : CustomerForm Form = new CustomerForm(m_CustomerDT[DataGrdVw.SelectedRows[0].Index]); : Form.ShowDialog(); In the CustomerForm_Load handler I initialize my CustomerForm controls like : if (!m_CustomerRow.IsNull("LastName")) { LastNameTxtBx.Text = m_CustomerRow.LastName; : } In the OKButton_Click handler I do the opposite, saving the values back in the DataRow. Everything works fine that way, but is it the correct way to go ?? Shouldn't I use DataBindings, BindingContext's, CurrencyManagers etc ... If so, why and how should that translate for my context ?
-
Just curious. I have a master form with a DataGridView on it showing me the records of a DataTable. The same form also holds 3 buttons. (An "Insert", "Update" and "Delete" button). Clicking "Insert" I do : CustomerForm Form = new CustomerForm(m_CustomerDT.NewCustomerRow()); : if (Form.ShowDialog() == DialogResult.OK) m_CustomerDT.AddCustomerRow(Form.CustomerRow); Clicking "Update" I do : CustomerForm Form = new CustomerForm(m_CustomerDT[DataGrdVw.SelectedRows[0].Index]); : Form.ShowDialog(); In the CustomerForm_Load handler I initialize my CustomerForm controls like : if (!m_CustomerRow.IsNull("LastName")) { LastNameTxtBx.Text = m_CustomerRow.LastName; : } In the OKButton_Click handler I do the opposite, saving the values back in the DataRow. Everything works fine that way, but is it the correct way to go ?? Shouldn't I use DataBindings, BindingContext's, CurrencyManagers etc ... If so, why and how should that translate for my context ?
I'd say in a Windows Forms project that is perfectly acceptable and gives you the control you need to validate the data entered. In WPF however you really want to take advantage of the binding model within WPF and MVVM. I have heard that people are successfully implementing MVVM in Windows Forms which would be a nice way to go.
"You get that on the big jobs."