• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1271
  • Last Modified:

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);
                }
            }

        }
0
finance_teacher
Asked:
finance_teacher
  • 5
  • 4
1 Solution
 
zadeveloperCommented:
what type of object is: gML_ROITEMBindingSource
0
 
finance_teacherAuthor Commented:
It is the attached "Toolbox" CONTROL.
0001.jpg
0
 
zadeveloperCommented:
replace
gML_ROITEMBindingSource.RemoveCurrent();
with:
gML_ROITEMBindingSource.Clear();
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
zadeveloperCommented:
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

0
 
finance_teacherAuthor Commented:
gML_ROITEMBindingSource.Clear();

and

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

both fail

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

0
 
finance_teacherAuthor Commented:
Yes, remove ALL rows after the user SUBMITS
so the gML_ROITEMDataGridView is BLANK again so
the user can submit more records.
0
 
zadeveloperCommented:
ok : then you should not be calling RemoveCurrent on the binding source ... try below

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_ROITEMDataGridView.Rows.Clear();
                    //gML_ROITEMBindingSource.RemoveCurrent();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Assign Error-> " + ex.Message);
                }
            }

        }

Open in new window

0
 
finance_teacherAuthor Commented:
Still fails, but below is a SOLUTION I found.

SOLUTION
   myDataSet.<table name>.clear()

Example
  dataSet1.GML_ROITEM.Clear();
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now