Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

BindingSource and DataBinding

$
0
0

Hi folks,

Having a mental block here...

On my form I have a grid (grdMain) that has a datasource to a bindingSource (_bsMain). The bindingSource. datasource is a DataTable (_dtMain).

I also have some other controls that have DataBindings to the same BindingSource (_bsMain) for impi.

// Set the grids datasource to the binding source and the BindingSource to the DataTAble.
            _bsMain.DataSource = _dtMain;
            grdMain.DataSource = _bsMain;

            // Create DataBinds
            entVesselID.DataBindings.Add("Text", _bsMain, "vesselID");
            mskDate.DataBindings.Add("Text", _bsMain, "docDate");
            entRef1.DataBindings.Add("Text", _bsMain, "ref1");
            entRef2.DataBindings.Add("Text", _bsMain, "ref2");
            spnAtr.DataBindings.Add("Value", _bsMain, "atr");
            spnTotal.DataBindings.Add("Value", _bsMain, "total");

I simply want to add a new record and save it. I have an Add Button and a Save Button.

When I click the add button, what should I do? 

Should I call the _bsMain.AddNew method ? When I do this, I would expect the grid to add a blank row but it does not.

Or should I use this approach...

DataRow newRow = _dtMain.NewRow();
newRow["atr"] = atr;
_dtMain.Rows.Add(newRow);

Again, the grid does not add a row. 

Any ideas what I am doing wrong ?

Thanks,

J


jppnn


Viewing all articles
Browse latest Browse all 2535

Trending Articles