WinForm 2.0 无代码实现DataGridView数据和下拉框和文本框的同步

private void OnFormLoad(object sender, EventArgs e)
{
// Set up event handlers for connector position changed
// and text box text changed events
m_CustomersBindingSource.PositionChanged += OnPositionChanged;
m_PositionTextBox.TextChanged += OnPositionTextChanged;
// Set up data bindings
CustomersDataSet nwData = CustomersDataSet.GetCustomers();
m_CustomersGrid.DataSource = m_CustomersBindingSource;
m_CustomersBindingSource.DataSource = nwData.Customers;
AddTextBoxDataBindings();
AddComboBoxDataBindings();
}
private void AddTextBoxDataBindings()
{
m_CustomerIDTextBox.DataBindings.Add("Text",
m_CustomersBindingSource, "CustomerID");
m_CompanyNameTextBox.DataBindings.Add("Text",
m_CustomersBindingSource, "CompanyName");
m_ContactNameTextBox.DataBindings.Add("Text",
m_CustomersBindingSource, "ContactName");
m_ContactPhoneTextBox.DataBindings.Add("Text",
m_CustomersBindingSource, "Phone");
}
private void AddComboBoxDataBindings()
{
m_ContactsCombo.DataSource = m_CustomersBindingSource;
m_ContactsCombo.DisplayMember = "ContactName";
m_ContactsCombo.ValueMember = "CustomerID";
}
posted @ 2007-11-25 21:36  曹振华  阅读(889)  评论(0编辑  收藏  举报