如何在新表格的combox中显示datagridview的值

时间:2019-08-14 09:23:58

标签: c# datagridview combobox

我正在学习C#。我有一个Datagridview,其中装有产品,当我按Enter键时,我希望它打开另一个表格,其中包含我选择的产品的详细信息。第二个有一个组合框,其中必须显示物品的使用情况,而且我必须能够更改它。

我可以打开它,然后以第二种形式将部门的值分配给组合框。我也可以填充组合框。我的问题是我不能同时拥有两个。我希望组合框显示部门的当前值,当我单击它时,列表必须包含所有可用部门。请注意,部门是另一个表,库存是另一个表。使用MYSQL

private void dginventory_KeyDown(object sender, KeyEventArgs e)
    {
        MySqlConnection con = new MySqlConnection("server=localhost;user id=root;password=1234;database=fabtrader;sslMode=none");
        MySqlCommand cmd = new MySqlCommand("select * from tblinventory where tblinventory.invid='" + dginventory.CurrentRow.Cells[0].Value.ToString() + "'", con);

        frmviewinvdetails forminvdetopen = new frmviewinvdetails();

        if (e.KeyCode == Keys.Enter)
        {
            try
            {
                con.Open();
                using (MySqlDataReader read = cmd.ExecuteReader())
                {
                    while (read.Read())
                    {
                        forminvdetopen.txtinvid.Text = (read["invid"].ToString());
                        forminvdetopen.txtinvcode.Text = (read["InventoryCode"].ToString());
                        forminvdetopen.txtInvDescription.Text = (read["InvDescription"].ToString());
                        forminvdetopen.txtInvShortText.Text = (read["InvShortText"].ToString());
                        string units = "select * from tblunits where unitid='" + read["UnitId"].ToString() + "'";
                        performcrud.fill_CBO(units, forminvdetopen.cbunits);

                    }
                    read.Close();
                }


                //SqlConfig performcrud = new SqlConfig();
                //string units = "select unitid,unitdescription from tblunits";
                //performcrud.fill_CBO(units, forminvdetopen.cbunits);
                //forminvdetopen.cbunits.Text = "test";


            }
            catch (Exception)
            {

                throw;
            }
            e.SuppressKeyPress = true;
        }

        forminvdetopen.ShowDialog();
    }

我希望打开“产品详细信息”表单,并显示来自datagridview和部门的值,以便在组合框中显示所选项目。当我单击组合框时,列表中必须包含部门表中的所有部门。

我可以显示所选部门,也可以用部门列表填充组合框。但我希望它同时执行两个操作。

0 个答案:

没有答案