首页 > 解决方案 > 如何在过滤的 AdvanceDataGridView 中添加新行

问题描述

我试图在已绑定数据的过滤后的 datagridview 中添加一个新 ROW。

这就是我填充数据的方式

 private void populateTAble()
    {
        string getData = "Select ID,Name_OF_Peoples_Organization AS 'Name of Peoples Organization',Representative_Name as 'Representative Name',Sex as 'Gender',Category,Barangay,Municipality,Year,Office,Taget_Has AS 'Target (has.)', " +
            "Accomplishment_Has as 'Accomplishment (has.)',Target_Seedlings as 'Target (Seedling)'," +
            "Accomplishment_Seedlings AS 'Accomplishment (Seedling)',Commodity_Species_Planted as 'Commodity Species Planted'," +
            "Year_1 as 'Year 1',Year_2 as 'Year 2',Year_3 as 'Year 3',grand_total as 'Grand Total',Remarks_Status as 'Remarks/Status' from ngp";
        try
        {
            conn = new MySqlConnection(connectString);
            conn.Open();
            adapter = new MySqlDataAdapter(getData, conn);
            NGPdataset = new DataSet();

            adapter.Fill(NGPdataset);
            advancedDataGridView1.DataSource = NGPdataset.Tables[0];

            ngpclass.NGPTotals(NGPdataset, advancedDataGridView1);

            conn.Close();
            totalss();

        }
        catch (Exception ee)
        {
            MessageBox.Show(ee.Message);
        }
    }

其次是使用AdvanceDataGridview过滤器过滤

 private void AdvancedDataGridView1_FilterStringChanged(object sender, EventArgs e)
    {
        BindingSource bind = new BindingSource();
        bind.DataSource = advancedDataGridView1.DataSource;
        bind.Filter = this.advancedDataGridView1.FilterString;
    }

现在数据已被过滤我想在 datagridview 中添加一个新行,并在按钮单击中使用它

DataTable dt = (DataTable)advancedDataGridView1.DataSource;
             DataRow toInsert = dt.NewRow();
             toInsert[1] = "New Row";
             dt.Rows.Add(toInsert);
             advancedDataGridView1.Refresh();

运行上述代码后没有结果或任何错误,也没有添加新行

标签: c#rowfiltering

解决方案


推荐阅读