DataGridViewComboBoxColumn不更新

时间:2015-11-18 18:17:25

标签: c# datagridcomboboxcolumn

我有ProcurementFrm列出

中的可用项目
DataGridViewComboBoxColumn 

使用此方法:

  /**
       Populate combo box in datagrid in procurement screen
      */
    public void populateGridComboBox()
    {
        con.Open();
        MySqlCommand sc = new MySqlCommand("select id, ar_desc from minierp_db.items", con);
        //MySqlDataReader reader;
        MySqlDataReader itemReader = null;

        try
        {
            itemReader = sc.ExecuteReader();

            itemDT = new DataTable();

            itemDT.Columns.Add("id", typeof(string));
            itemDT.Columns.Add("ar_desc", typeof(string));
            itemDT.Load(itemReader);

            itemIDcmbColmn.ValueMember = "id";
            itemIDcmbColmn.DisplayMember = "ar_desc";
            itemIDcmbColmn.DataSource = itemDT;
        }
        catch (Exception e)
        {
            MessageBox.Show("Exception - populateGridComboBox(): " + e.Message);
        }
        finally
        {
            con.Close();
            itemReader.Dispose();
        }
    } //populateGridComboBox

并以相同的形式我有一个按钮,调用另一个形式addItemFrm,使用户可以添加一个新项目。该项目已正确添加,但在我关闭并重新打开ProcurementFrm之前,它并未直接反映在ComboBoxColumn中。

这里我将如何将新项目添加到ComboBoxColumn

  public void populateNewAddedItems()
    {
        procurmentsFrm prcFrm = (procurmentsFrm)Application.OpenForms["procurmentsFrm"];
        MySqlConnection connn = new MySqlConnection("datasource=127.0.0.1;port=3306;username=root;password=admin");
        MySqlCommand sc = new MySqlCommand("select id, ar_desc from minierp_db.items", connn);


        //itemDT = new DataTable();
        try
        {
            DataGridViewComboBoxColumn itemCmbClmn = new DataGridViewComboBoxColumn();


            itemCmbClmn.ValueMember = itemID.ToString();
            itemCmbClmn.DisplayMember = txtItemAr.Text;

            BindingSource bs = new BindingSource();
            DataTable itemDataTable = prcFrm.ItemData;
            bs.DataSource = itemDataTable;
            itemCmbClmn.DataSource = bs;

请帮忙吗?我希望comboBox可以直接更新。

0 个答案:

没有答案