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"; }
长期招聘java,有找工作可以联系我,微信:caozhenhua1563