Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中带有报表的Datagridview#_C#_Data Binding_Datagridview_Datagrid_Reportviewer - Fatal编程技术网

C# C语言中带有报表的Datagridview#

C# C语言中带有报表的Datagridview#,c#,data-binding,datagridview,datagrid,reportviewer,C#,Data Binding,Datagridview,Datagrid,Reportviewer,我在Mysql中有一个表,有4列(id、nameofcase、priceone、pricetwo)。 我制作了一个dataGridView1,其中有一列,两列有priceone和pricetwo的按钮,我可以看到数据。 问题是,当我按下两个按钮中的一个时,我得到了我想要的信息。 如何将这些信息放入报告中? private void Form3_Load(object sender, EventArgs e) { // TODO: This line of

我在Mysql中有一个表,有4列(id、nameofcase、priceone、pricetwo)。 我制作了一个dataGridView1,其中有一列,两列有priceone和pricetwo的按钮,我可以看到数据。 问题是,当我按下两个按钮中的一个时,我得到了我想要的信息。 如何将这些信息放入报告中?

 private void Form3_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'lawyerspriceDataSet.lawsuit_under_500' table. You can move, or remove it, as needed.
            this.lawsuit_under_500TableAdapter.Fill(this.lawyerspriceDataSet.lawsuit_under_500);



        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        { 

            if (e.ColumnIndex == dataGridView1.Columns["priceoneDataGridViewTextBoxColumn"].Index)
              {

 //with those 2 lines i am getting the information's that i want

        dataGridView1.Rows[row].Cells[col - 1].Value.ToString();

      dataGridView1.Rows[row].Cells[col].Value.ToString();

   }
  else if (e.ColumnIndex == dataGridView1.Columns["pricetwoDataGridViewTextBoxColumn"].Index)
  {

      dataGridView1.Rows[row].Cells[col - 2].Value.ToString();

      dataGridView1.Rows[row].Cells[col].Value.ToString();


  }
}

        }




private void button1_Click(object sender, EventArgs e)
        {
            Form4 report = new Form4();
            report.Show();
        }

有人知道我怎么做吗?

试试这个:

 private void dataGridview_CellClick(object sender, DataGridViewCellEventArgs e)
            {
    if (e.ColumnIndex == dataGridview.Columns["btnName"].Index)
                    {
                        DataGridViewRow dr=dataGridview.Rows[e.RowIndex];
    //do ur stuffs
            }

    }

您似乎知道DataGridViewCellEventArgs保存着行索引,如何从该行获取数据是一个问题?不,我不知道DataGridViewCellEventArgs。在代码中,我做了一个注释,我在web中找到了它,并使用该messageBox对其进行了测试,它在'if(e.ColumnIndex==dataGridview.Columns[“btnName”].Index)行中工作“它表示对象引用未设置为对象的实例。您是否更改了datagridview名称并在该字符串中指定了正确的列名?我已更改了它们,正确的列名为priceoneDataGridViewTextBoxColumn,现在可以了。但问题是,当我按下两个按钮之一时,我想用具体的案件名称和价格,并把它放在一个报告,以便以后可以打印它纠正我,如果我错了。。如果单击第2列和第3列中的任何一个按钮,您想要第1列的值吗?第1列的值和第2列或第3列的值取决于单击的列