【发布时间】:2018-09-13 19:57:03
【问题描述】:
我将数据网格中的 variás 选择项传递给另一个表单,但是我需要第二个表单只打开一次。我把 Form 调用放在
foreach (DataGridViewRow row in dgvcontasreceber.SelectedRows)
{
SqlConnection conConexao1 = clsdb.AbreBanco();
SqlCommand cmd1 = new SqlCommand("select dbo.empresas.id, dbo.empresas.razao_social from empresas inner join dbo.pessoa_empresa on dbo.pessoa_empresa.empresa_id = dbo.empresas.id inner join dbo.pessoa on dbo.pessoa.id = dbo.pessoa_empresa.pessoa_id where dbo.pessoa.id ='" + lblid.Text + "'", conConexao1);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.HasRows == true)
{
if (dr1.Read())
{
var item = new clsItens
{
PessoaId = txtid.Text,
EmpresaId = int.Parse(dr1[0].ToString()),
RazaoSocial = dgvcontasreceber[0, linhaAtual].Value.ToString()
};
items.Add(item);
}
}
dr1.Close();
cmd1.Clone();
conConexao1.Close();
}
FormRecebimento abrir = new FormRecebimento(items);
abrir.ShowDialog();
【问题讨论】:
-
有什么问题?期望的结果是什么?
-
问题是你多次打开第二个表单,我希望它只打开一次但传递所有的foreach数据。
-
但是您的 FormRecebimento 只能接受 1 行数据,它将如何显示所有行的数据?
-
这是真的,我试图通过一个 prorem 数组,即使我正在传递一个值。这就是为什么我想知道如何转到另一种形式。
-
您必须更改您的 FormRecebimento 以接受多行。然后您可以将所有行传递给表单,您将不再需要 foreach 循环。但是,如果您的 FormRecebimento 必须显示一组行而不是单个行,则它的外观必须非常不同。