c# - 如何在过滤的 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();
运行上述代码后没有结果或任何错误,也没有添加新行
解决方案
推荐阅读
- r - 从Linux系统上的R闪亮downloadHandler中删除目录结构
- python - Python FBProphet ValueError:必须通过二维输入
- java - 使用 java 解析 USvideos.csv 文件
- javascript - FCM Web 转换 Android webview
- c - 不知道如何检查 C 中的输入参数
- javascript - 调用 Firebaseui start(...) 时的 preventScroll
- reactjs - Axios - 被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头
- powershell - Powershell中变量定义的文件路径内的Out-File文本输入
- python - 获取数据框列中的类型列表,跳过 NaN 单元格
- python-3.x - 将答案四舍五入到小数点后两位