我在表单1中公开了我的dataGridView,我可以从第二个表单访问其HeaderText
但我无法访问dataGridView
的任何其他属性/值。
我通过int gridLoopCount = dataGridView1.Rows.Count-1;
所以,我的循环工作,我通过更改我的图形字符串e.Graphics.DrawString("my value"......
以下是表单2的代码:
//Drawing the data grid
Recieve_Donation_Stock rds = new Recieve_Donation_Stock();
e.Graphics.DrawString(label7.Text, label7.Font, Brushes.Black, (tableLayoutPanel2.Location.X + label7.Location.X), (tableLayoutPanel2.Location.Y + label7.Location.Y));
e.Graphics.DrawString(rds.dataGridView1.Columns[1].HeaderText, label9.Font, Brushes.Black, (tableLayoutPanel2.Location.X + label9.Location.X), (tableLayoutPanel2.Location.Y + label9.Location.Y));
e.Graphics.DrawString(rds.dataGridView1.Columns[2].HeaderText, label10.Font, Brushes.Black, (tableLayoutPanel2.Location.X + label10.Location.X), (tableLayoutPanel2.Location.Y + label10.Location.Y));
int j = 1;
for (int i = 0; i <=gridLoopCount; i++)
{
e.Graphics.DrawString(i.ToString(), label13.Font, Brushes.Black, (tableLayoutPanel2.Location.X + label7.Location.X), (tableLayoutPanel2.Location.Y + label7.Location.Y + (15*j)));
e.Graphics.DrawString(rds.dataGridView1.Rows[i].Cells[0].Value.ToString(), label13.Font, Brushes.Black, (tableLayoutPanel2.Location.X + label9.Location.X), (tableLayoutPanel2.Location.Y + label9.Location.Y + (15 * j)));
e.Graphics.DrawString(rds.dataGridView1.Rows[i].Cells[1].Value.ToString(), label13.Font, Brushes.Black, (tableLayoutPanel2.Location.X + label10.Location.X), (tableLayoutPanel2.Location.Y + label10.Location.Y + (15 * j)));
j++;
}