Search code examples
c#datagridviewresetbindingsourcestrongly-typed-dataset

How to clear the added rows from a datagridview binded using a BindingSource c# .net


Its a Windows Form Application. Database is MS Access. Using Typed DataSet. I am having a datagridview, which i only use to insert data into database. I want to clear all the rows added as soon as I click on Reset Button on my form. The datagridview is using bindingSource. The Binding Source is using a Typed DataTable from the Typed DataSet


Solution

  • For the following scenario

    this.dataGridViewPurDetails.DataSource = this.purchaseDetailBindingSource; 
    // purchaseDetailBindingSource 
    // this.purchaseDetailBindingSource.DataMember = "PurchaseDetail";
    this.purchaseDetailBindingSource.DataSource = this.tVDataSet;
    

    This Solution Worked
    //Clear All the rows from the datagridview

    BindingSource DT = (BindingSource)dataGridViewPurDetails.DataSource; 
    if (DT != null) 
        ((TVDataSet)DT.DataSource).PurchaseDetail.Clear();