Link to home
Start Free TrialLog in
Avatar of finance_teacher
finance_teacher

asked on

C# -- BindingSource -- "RemoveCurrent" ?

The below "gML_ROITEMBindingSource.RemoveCurrent();"
only removes the current ROW.

How can I remove ALL rows after the user SUBMITS
so the gML_ROITEMDataGridView is BLANK again so
the user can submit more records ?
------------------------------------------------------------------
        private void btn_Submit_Click(object sender, EventArgs e)
        {
            if (cboVendor.Text == "")
            {
                MessageBox.Show("Enter a vendorNumber");
                return;
            }
            else
            {
                this.Validate();
                decimal iGML_ROMSTR_ID = 0;
                try
                {
                    DataSet1TableAdapters.GML_SEQ_ROMSTRTableAdapter adpSeq = new OrderEntry.DataSet1TableAdapters.GML_SEQ_ROMSTRTableAdapter();
                    DataSet1.GML_SEQ_ROMSTRDataTable tb = adpSeq.GetData();

                    if (tb != null && tb.Rows.Count > 0)
                    {
                        if (tb.Rows[0][0] != DBNull.Value)
                        {
                            iGML_ROMSTR_ID = Convert.ToDecimal(tb.Rows[0][0]);
                        }
                    }
                    decimal TEMP_locNum = 0;
                    decimal TEMP_palletsReq = 0;
                    decimal TEMP_imId = 0;
                    string TEMP_Priority = String.Empty;
                    decimal TEMP_vendId = 0;

                    for (int i = 0; i < gML_ROITEMDataGridView.Rows.Count - 1; i++)
                    {
                        // change below [] when column NAME changes
                        TEMP_locNum = (decimal)this.gML_ROITEMDataGridView["LOC_NUM", i].Value;
                        TEMP_imId = (decimal)this.gML_ROITEMDataGridView["IM_ID", i].Value;
                        TEMP_palletsReq = (decimal)this.gML_ROITEMDataGridView["PALLETSREQ", i].Value;
                        TEMP_Priority = this.gML_ROITEMDataGridView["PRIORITY", i].Value.ToString();
                        TEMP_vendId = (decimal)this.gML_ROITEMDataGridView["VENDNO", i].Value;
                        //below inserts locnum-itemID-pallets-pri-date-user-RO#-vend#
                        this.gML_ROITEMTableAdapter.InsertQuery(TEMP_locNum, 177982, TEMP_palletsReq, TEMP_Priority, DateTime.Today, 42, iGML_ROMSTR_ID, TEMP_vendId);
                    }
                    gML_ROITEMBindingSource.RemoveCurrent();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Assign Error-> " + ex.Message);
                }
            }

        }
Avatar of Jarrod
Jarrod
Flag of South Africa image

what type of object is: gML_ROITEMBindingSource
Avatar of finance_teacher
finance_teacher

ASKER

It is the attached "Toolbox" CONTROL.
0001.jpg
replace
gML_ROITEMBindingSource.RemoveCurrent();
with:
gML_ROITEMBindingSource.Clear();
or:
private void btn_Submit_Click(object sender, EventArgs e)
        {
            if (cboVendor.Text == "")
            {
                MessageBox.Show("Enter a vendorNumber");
                return;
            }
            else
            {
                this.Validate();
                decimal iGML_ROMSTR_ID = 0;
                try
                {
                    DataSet1TableAdapters.GML_SEQ_ROMSTRTableAdapter adpSeq = new OrderEntry.DataSet1TableAdapters.GML_SEQ_ROMSTRTableAdapter();
                    DataSet1.GML_SEQ_ROMSTRDataTable tb = adpSeq.GetData();

                    if (tb != null && tb.Rows.Count > 0)
                    {
                        if (tb.Rows[0][0] != DBNull.Value)
                        {
                            iGML_ROMSTR_ID = Convert.ToDecimal(tb.Rows[0][0]);
                        }
                    }
                    decimal TEMP_locNum = 0;
                    decimal TEMP_palletsReq = 0;
                    decimal TEMP_imId = 0;
                    string TEMP_Priority = String.Empty;
                    decimal TEMP_vendId = 0;

                    for (int i = 0; i < gML_ROITEMDataGridView.Rows.Count - 1; i++)
                    {
                        // change below [] when column NAME changes
                        TEMP_locNum = (decimal)this.gML_ROITEMDataGridView["LOC_NUM", i].Value;
                        TEMP_imId = (decimal)this.gML_ROITEMDataGridView["IM_ID", i].Value;
                        TEMP_palletsReq = (decimal)this.gML_ROITEMDataGridView["PALLETSREQ", i].Value;
                        TEMP_Priority = this.gML_ROITEMDataGridView["PRIORITY", i].Value.ToString();
                        TEMP_vendId = (decimal)this.gML_ROITEMDataGridView["VENDNO", i].Value;
                        //below inserts locnum-itemID-pallets-pri-date-user-RO#-vend#
                        this.gML_ROITEMTableAdapter.InsertQuery(TEMP_locNum, 177982, TEMP_palletsReq, TEMP_Priority, DateTime.Today, 42, iGML_ROMSTR_ID, TEMP_vendId);

                    }
                    //gML_ROITEMBindingSource.RemoveAt(i);
foreach (BindingSource source in gML_ROITEMBindingSource.List)
                gML_ROITEMBindingSource.Remove(source);

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Assign Error-> " + ex.Message);
                }
            }

        }

Open in new window

gML_ROITEMBindingSource.Clear();

and

foreach (BindingSource source in gML_ROITEMBindingSource.List)
                gML_ROITEMBindingSource.Remove(source);

both fail

ATTACHED
0002.jpg
0003.jpg
are you trying to remove the rows from the grid ?

Yes, remove ALL rows after the user SUBMITS
so the gML_ROITEMDataGridView is BLANK again so
the user can submit more records.
ASKER CERTIFIED SOLUTION
Avatar of Jarrod
Jarrod
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Still fails, but below is a SOLUTION I found.

SOLUTION
   myDataSet.<table name>.clear()

Example
  dataSet1.GML_ROITEM.Clear();