public void IsBindingSuspendedTest() { Control c = new Control(); c.BindingContext = new BindingContext(); MockItem item = new MockItem("A", 0); MockItem [] items = new MockItem [] { item }; BindingManagerBase manager = c.BindingContext [item]; BindingManagerBase manager2 = c.BindingContext [items]; Assert.IsFalse(manager.IsBindingSuspended, "#A1"); Assert.IsFalse(manager2.IsBindingSuspended, "#A2"); manager.SuspendBinding(); manager2.SuspendBinding(); Assert.IsFalse(manager.IsBindingSuspended, "#B1"); Assert.IsTrue(manager2.IsBindingSuspended, "#B2"); manager.ResumeBinding(); manager2.ResumeBinding(); Assert.IsFalse(manager.IsBindingSuspended, "#C1"); Assert.IsFalse(manager2.IsBindingSuspended, "#C2"); }
/// <summary> /// Handles the ItemCheck event of the cblCategories control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ItemCheckEventArgs"/> instance containing the event data.</param> void cblCategories_ItemCheck(object sender, ItemCheckEventArgs e) { //finding out which category we are talking about Category category = this.cblCategories.Items[e.Index] as Category; BindingManagerBase bindingContext = this.gvProducts.BindingContext[this.gvProducts.DataSource]; if (category != null) { //getting all rows that contains products with the category weare dealing with string categoryColName = DataTableConstans.COL_NAME_CATEGORYOBJECT; IEnumerable <DataGridViewRow> enumeratedRows = this.gvProducts.Rows.Cast <DataGridViewRow>().Where(row => (row.Cells[categoryColName].Value as Category) != null && (row.Cells[categoryColName].Value as Category).guid == category.guid); List <DataGridViewRow> relevantRows = enumeratedRows.ToList(); //setting visibility bool showRows = e.NewValue == CheckState.Checked; bindingContext.SuspendBinding(); this.gvProducts.SuspendLayout(); //relevantRows.ForEach(row => row.Visible = showRows); foreach (DataGridViewRow currRow in relevantRows) { currRow.Visible = showRows; } this.gvProducts.ResumeLayout(true); bindingContext.ResumeBinding(); } }
private void setLogOption() { BindingManagerBase bmOrders = logForm.BindingContext[log.getLogList()]; bmOrders.SuspendBinding(); logOptChosen.SetName(txtLogName.Text); logOptChosen.SetFileName(txtLogFileName.Text); logOptChosen.SetEnabled(chkEnableLog.Checked); List <Logger.LoggingOption> options = logOptChosen.getOptions(); System.Collections.IEnumerator myEnumerator = options.GetEnumerator(); while (myEnumerator.MoveNext()) { Logger.LoggingOption option = (Logger.LoggingOption)(myEnumerator.Current); int idx = lstOptions.Items.IndexOf(option); bool sel = lstOptions.GetSelected(idx); int idx2 = options.IndexOf(option); //options[idx2].SetEnabled(sel); option.enabled = sel; } bmOrders.ResumeBinding(); //logFrm.setLogOption(logOptChosen); }
//This causes the results list to refreash incase items are removed etc. public void refreshBindings() { BindingManagerBase bmb = this.ResultsDataGridView.BindingContext[this.view]; bmb.SuspendBinding(); bmb.ResumeBinding(); }
private void InitTargetNum() { BindingManagerBase bindMB = cmbTarget.BindingContext[contactList]; bindMB.SuspendBinding(); bindMB.ResumeBinding(); cmbTarget.DataSource = contactList; cmbTarget.DisplayMember = "DisplayName"; }
private void ContactListBindData() { BindingManagerBase bindMB = listContactList.BindingContext[contactList]; bindMB.SuspendBinding(); bindMB.ResumeBinding(); listContactList.DataSource = contactList; listContactList.DisplayMember = "DisplayName"; }
private void btnAddToDomainFilterList_Click(object sender, EventArgs e) { if (this.tbDomain.Text != "") { this.xa.Settings.domainFilters.Add(this.tbDomain.Text); this.tbDomain.Text = ""; BindingManagerBase bmb = this.lbDomainFilters.BindingContext[this.xa.Settings.domainFilters]; bmb.SuspendBinding(); bmb.ResumeBinding(); } }
private void btnRemoveDomainFilter_Click(object sender, EventArgs e) { if (this.lbDomainFilters.SelectedIndex >= 0) { string s = this.xa.Settings.domainFilters[this.lbDomainFilters.SelectedIndex]; this.tbDomain.Text = s; this.xa.Settings.domainFilters.Remove(s); BindingManagerBase bmb = this.lbDomainFilters.BindingContext[this.xa.Settings.domainFilters]; bmb.SuspendBinding(); bmb.ResumeBinding(); } }
// <Snippet1> private void button3_Click(object sender, EventArgs e) { try { BindingManagerBase myBindingManager1 = BindingContext [myDataSet, "Customers"]; myBindingManager1.SuspendBinding(); } catch (Exception ex) { MessageBox.Show(ex.Source); MessageBox.Show(ex.Message); } }
//将适合过滤条件的数据显示在DataGridView中 void ShowGoods() { BindingManagerBase cm = (CurrencyManager)BindingContext[dataGridView1.DataSource]; cm.SuspendBinding(); //挂起数据绑定 //FillGoodsTypeList(); //将选择的类别列表填充完整 //MessageBox.Show("Show:"+l_GoodsTypeList.Count.ToString()); int row = dataGridView1.Rows.Count; //得到总行数 for (int i = 0; i < row; i++) { //MessageBox.Show(dataGridView1.Rows[i].Cells[3].Value.ToString()); bool sFlag = true; if (b_HideZeroStock) { string ts = dataGridView1.Rows[i].Cells["LastQty"].Value.ToString(); //检测0库存 if (ts == "0") { sFlag = false; goto DoShow; } } int tGID = Convert.ToInt32(dataGridView1.Rows[i].Cells["GoodsID"].Value.ToString()); //检测货品类别 int tiTypeID = Convert.ToInt32(dataGridView1.Rows[i].Cells["GoodsTypeID"].Value.ToString()); if (!l_GoodsTypeList.Contains(tiTypeID)) { sFlag = false; goto DoShow; } //检测品名过滤 string s1 = dataGridView1.Rows[i].Cells["GoodsName"].Value.ToString(); string s2 = textBoxFindGoods.Text.Trim(); if (s1.IndexOf(s2) == -1) { sFlag = false; goto DoShow; } DoShow: dataGridView1.Rows[i].Visible = sFlag; } cm.ResumeBinding(); //恢复数据绑定 }
private void btnAddNew_Click(object sender, EventArgs e) { string newLogName = "Log " + (cmbLog.Items.Count); if (!cmbLog.Items.Contains(newLogName)) { // Helps in repopulating of combobox. BindingManagerBase bmOrders = this.BindingContext[log.getLogList()]; bmOrders.SuspendBinding(); log.AddNewLogger(newLogName); bmOrders.ResumeBinding(); } else { MessageBox.Show("?"); return; } cmbLog.SelectedItem = log.FindLogger(newLogName); logOptChosen = (Logger)cmbLog.SelectedItem; if (logOption == null || logOption.IsDisposed) { logOption = new EditLogForm(log, logOptChosen, this); } logOption.Show(); /* * if (addOption == null || addOption.IsDisposed) * { * addOption = new AddLogForm(this, log); * } * addOption.Show(); * */ }