datagridview to reportviewer C#
本文关键字:reportviewer to datagridview | 更新日期: 2023-09-27 18:11:22
我需要将数据从datagridview传输到reportviewer。我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//dataGridView1.AutoGenerateColumns = false;
dataGridView1.Columns.Add("test");
dataGridView1.Columns.Add("One");
dataGridView1.Columns.Add("two");
dataGridView1.Columns.Add("three");
dataGridView1.Columns.Add("four");
dataGridView1.Columns.Add("five");
dataGridView1.Columns.Add("six");
dataGridView1.Rows.Add("test", "test ", "1", "2", "3", "4");
dataGridView1.Rows.Add(980, 10, 70, 20, 50);
dataGridView1.Rows.Add(860, 20, 50, 60, 35);
dataGridView1.Rows.Add(950, 80, 35, 30, 40);
dataGridView1.Rows.Add(800, 40, 90, 30, 25);
dataGridView1.Rows.Add(900, 20, 45, 30, 60);
dataGridView1.Rows.Add(300, 20, 20, 20, 20);
dataGridView1.Rows.Add("check" , 50, 80, 50, 70);
}
}
这些参考没有帮助:如何从DataGridView到ReportViewer传递数据表
显示数据从datagridview到reportviewer c#如何显示数据从datagridview到reportviewer c# ?
您正在尝试直接添加到dataGridView
尝试从列表中添加它。
添加列
DataGridViewColumn columnTime = new DataGridViewTextBoxColumn();
columnTime .DataPropertyName = "Time";
columnTime .Name = "Time:";
dataGridView.Columns.Add(columnTime );
然后将其添加到DataGridView
var bindTime= new BindingList<Time>(listTime);
var sourceTime= new BindingSource(bindTime, null);
dataGridView.DataSource = sourceTime;
对ReportViewer使用相同的方法,如果您需要向DataGridView添加新内容,只需添加到IList并刷新DataGrid和ReportViewer
我想这比单独添加每一行更容易