C # refreshing text field from BindingSource

I'm having difficulty updating Windows stationery controls that use the BindingSource object. We have a CAB / MVP / SCSF client that I (actually "we", as this is a team) are developing that will interact with WCF services running on a remote server. (This is our first attempt, so we are in training mode). One of the calls (from Presenter) to the service returns a DataSet, which contains 3 DataTables called "Contract", "Credit" and "Conditions". Each table contains only one row. When a service returns a dataset, we store it in SmartPart / View in a member variable of the class by calling a function in the BindData () view and passing the dataset to the view from the presenter class;

private System.Data.DataSet _ds = null;
public void BindData(System.Data.DataSet ds)
{
    string sErr = "";
    try
    {
        _ds = ds;  // save to private member variable

        // more code goes down here
    }
}

DataTables Windows Forms TextBoxes, MaskedEditBoxes Infragistics UltraComboEditor. BindingSource, DataTable, VS2008.

private System.Windows.Forms.BindingSource bindsrcContract;
private System.Windows.Forms.BindingSource bindsrcLoan;
private System.Windows.Forms.BindingSource bindsrcTerms;

,

if (bindsrcContract.DataSource == null)
{
    bindsrcContract.DataSource = _ds;
    bindsrcContract.DataMember = "contract";

    txtContract.DataBindings.Add(new Binding("Text", bindsrcContract, "contract_id", true));                       

    txtLateFeeAmt.DataBindings.Add(new Binding("Text", bindsrcContract, "fee_code", true));

    txtPrePayPenalty.DataBindings.Add(new Binding("Text", bindsrcContract, "prepay_penalty", true));

    txtLateFeeDays.DataBindings.Add(new Binding("Text", bindsrcContract, "late_days", true));
}

if (bindsrcLoan.DataSource == null)
{
    bindsrcLoan.DataSource = _ds;
    bindsrcLoan.DataMember = "loan";

    mskRecvDate.DataBindings.Add(new Binding("Text", bindsrcLoan, "receive_date", true));

    cmboDocsRcvd.DataBindings.Add(new Binding("Value", bindsrcLoan, "docs", true));     
}

, . , , "", WCF.

. DataSet, 3 , ( , ..) , , smartPart/View - , . , DataSet.

, , , - . BindingSource.

bindsrcContract.ResetBindings(false);

bindsrcContract.ResetBindings(true);

bindsrcContract.RaiseListChangedEvents = true;

for (int i = 0; i < bindsrcContract.Count; i++)
{
    bindsrcContract.ResetItem(i);
}

DataMember.

bindsrcContract.DataMember = "Contract";

. BindingNavigator, DataTables , , . , . - , , , ?

VisualStudio 2008, # .Net 2.0, XP, W2K3.

Wes

+3
5

, .

private void btnCancel_Click(object sender, EventArgs e)
{
    this.MyTable.RejectChanges();
    this.txtMyBoundTextBox.DataBindings[0].ReadValue();
    this.EditState = EditStates.NotEditting;
}
+2

: . , . .

, , ( "", ).

, .

, , , , code-sample ( ), . , .

: , Binding-Manager .

_ds , Binding-Manager DataSet . DataSet _ds, Binding-Manager . - DataSet. , , reset DataSource DataSet.

, . , Binding-Manager ( ). . _ds , _ds DataSet, . Binding-Manager , , .

( PropertyChanged-Event, Binding-Manager), , DataSource.

, , , , . , WinForms ( ).

+1

DataSource , , - :

bindsrcContract.DataSource = typeof(System.Data.DataSet);
bindsrcContract.DataSource = _ds;

( , DataMember , DataSource .)

0

, , . , , , ...

, , :

  • DataSource, DataMember, , DataMember () . , DataMember ( DataSource, typeof (YourData)), , DataSource.

  • , .

    bindsrcContract.DataSource = _ds;
    

    ,

    bindsrcContract.DataSource = typeof(System.Data.DataSet);
    bindsrcContract.DataSource = _ds;
    
  • , , , MSDN, . . , - .

0

:

bindingsource.EndEdit() // writting data to underlying source 
bindingSource.ResetBindings(false)  // force controls to reread data from bindingSource

, - .

0

Source: https://habr.com/ru/post/1698829/


All Articles