日期:2014-05-19  浏览次数:20818 次

想让DataGridView只显示出查询结果应该怎样做?
查询完成后,DataGridView上显示出了想查询的内容,再进行下一次查询时让DataGridView只显示出这一次新查询出来的结果,这个应该怎样做啊

------解决方案--------------------
每次查询的时候都重新绑定一下数据源就可以了
------解决方案--------------------
DataGridView.DataBind()每次邦定都都要加这个!
------解决方案--------------------
DataGridView.DataSource = DataTable;
DataGridView.DataBind();
------解决方案--------------------
查询一次,绑定一次,如下: //dataGridView 数据源已绑定 this.bindingSource
protected virtual void SetDataSource(string strSql, string strWhere, string strOrder, bool isFirstLoad)
{
if (m_BLLCommon == null) return;

this.dataSet = m_BLLCommon.GetDataSet(strSql, strWhere, strOrder, isFirstLoad);
this.bindingSource.DataSource = this.dataSet.Tables[0].DefaultView;
this.bindingSource_PositionChanged(null, null);
}
------解决方案--------------------
DataGridView.DataSource重新设置一下就行了。

要注意数据源应该使用New新建立一个,否则可能会把上一次的数据合并起来。比如DataSet会自动的合并原来的数据。