I need code for selected in datagridview and after selected print in XtraReport. This way I pick up the selected rows, what do I need next?
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
bool isCellChecked = Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value);
if (isCellChecked == true)
{
var allCheckedRows = this.dataGridView1.Rows.Cast<DataGridViewRow>()
.Where(row => (bool?)row.Cells[0].Value == true)
.ToList();
This solution worked fine for me in WinForms …
To select Visible in Gridview:
private DataTable GetVisible()
{
//Export GRIDVIEW to DataTable
DataTable DT = new DataTable();
foreach (GridColumn column in gridView1.VisibleColumns)
{
DT.Columns.Add(column.FieldName, column.ColumnType);
}
for (int i = 0; i < gridView1.DataRowCount; i++)
{
DataRow row = DT.NewRow();
foreach (GridColumn column in gridView1.VisibleColumns)
{
row[column.FieldName] = gridView1.GetRowCellValue(i, column);
}
DT.Rows.Add(row);
}
return DT;
}
To show Preview form:
private void FullBtnView_Click(object sender, EventArgs e)
{
Reports.FullList Rep = new Reports.FullList
{
DataSource = GetVisible()
};
using (ReportPrintTool printTool = new ReportPrintTool(Rep))
{
// Invoke the Print Preview form
// with the specified look and feel setting.
printTool.ShowPreviewDialog(UserLookAndFeel.Default);
}
}
To Print data:
private void FullBtnPrint_Click(object sender, EventArgs e)
{
Reports.FullList Rep = new Reports.FullList
{
DataSource = GetVisible()
};
using (ReportPrintTool printTool = new ReportPrintTool(Rep))
{
// Invoke the Print Preview form
// with the specified look and feel setting.
printTool.Print();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.