MessageBox.Show(this.dataSet1.Tables[0].Rows[0].ItemArray[0].ToString());
this.dataSet1.Tables[0].DefaultView.Sort="用户名 desc";
MessageBox.Show(this.dataSet1.Tables[0].Rows[0].ItemArray[0].ToString());这是我测试的代码,排序后DATAGRID上的序顺变了。但this.dataSet1.Tables[0].Rows[0].ItemArray[0]对应的记录还是没变。
this.dataSet1.Tables[0].DefaultView.Sort="用户名 desc";
MessageBox.Show(this.dataSet1.Tables[0].Rows[0].ItemArray[0].ToString());这是我测试的代码,排序后DATAGRID上的序顺变了。但this.dataSet1.Tables[0].Rows[0].ItemArray[0]对应的记录还是没变。
{
//筛选选中数据到指定数据集中,再从该数据集中读取数据进行打印
DataSet ds1=ds.Clone();
for (int i=0;i<ds.Tables[tabName].Rows.Count-1;i++)
{
if (dg.IsSelected(i)==true)
{
ds1.Tables[tabName].NewRow();
ds1.Tables[tabName].Rows.Add(ds.Tables[tabName].Rows.Find(dg[i,0]).ItemArray);
}
}
ds1.Tables[tabName].AcceptChanges();crv.ReportSource=MyCr;
MyCr.SetDataSource(ds1.Tables[tabName]);}
ds1.Tables[tabName].Rows.Add(ds.Tables[tabName].Rows.Find(dg[i,0]).ItemArray);
这句代码最重要,作用就是把选中的数据行添加到打印数据表中去,ReportDocument MyCr就是你做的报表模板,本例采用水晶报表,调用如下:
printReport(dataSet1,dataGrid1,"department",MyCr,aform.crystalReportViewer1);
主意要将crystalReportViewer1设为public
rptDoc.Load(reportname);
rptDoc.SetDataSource=dgrd.DataSource;
rptDoc.PrintToPrinter(0);