1

我是新手,我需要一个详细的答案,对不起我的英语不好......我会尽力解释自己......我在 Mysql 中有 2 个表

 table1:  id_ticket , ticket_description, ticket_status(id_status)         
 table2 :    id_statu , status_name

在我的应用程序中,我使用 table1 中的所有信息来填充 DataGridView,还添加了一个组合框列,组合框显示 table2 中的“status_name”,我想用组合框中包含的信息修改 ticket_status,我该怎么做那?

这是我的代码:

public void CreateAssignedToMe(string ConnString)
    {
        string assignedTo = textBoxUid.Text;
        string query = "SELECT * FROM reports WHERE ticket_assignee='"+assignedTo+"' AND ticket_resolution < 3;";

        AssignToMe = new AssignedToMe();
        AssignToMe.ConnString = ConnString;
        DataGridView dgvReports = AssignToMe.dataGridViewAssignedToMe;

        try
        {
            MySqlConnection conn = new MySqlConnection(ConnString);
            conn.Open();
            MySqlDataAdapter daUsers = new MySqlDataAdapter(query,ConnString);
            DataSet dsUsers = new DataSet();
            daUsers.Fill(dsUsers,"report");
            dgvReports.DataSource = dsUsers;
            dgvReports.DataMember = "report";
            dgvReports.AllowUserToAddRows = false;
            dgvReports.AllowUserToDeleteRows = false;
            dgvReports.Columns["ticket_departmentResponsive"].Visible = false;
            dgvReports.Columns["ticket_assignee"].Visible = false;


                string queryStatus = "SELECT * FROM status";
                MySqlDataAdapter daStatus = new MySqlDataAdapter(queryStatus, ConnString);                  
                DataSet dsStatus = new DataSet();
                MySqlCommandBuilder builder = new MySqlCommandBuilder(daStatus);
                daStatus.Fill(dsStatus, "Resolution");

                daStatus.UpdateCommand = builder.GetUpdateCommand();

                DataGridViewComboBoxColumn cbbox = new DataGridViewComboBoxColumn();
                BindingSource StatusBindingSource = new BindingSource();
                StatusBindingSource.DataSource = dsStatus;
                StatusBindingSource.DataMember = "Resolution";
                cbbox.HeaderText = "Resolution";
                cbbox.DropDownWidth = 90;
                cbbox.DataSource = StatusBindingSource;
                cbbox.DisplayMember = "status_name";
                dgvReports.Columns.Add(cbbox);



            AssignToMe.ShowDialog();

        }
        catch(MySqlException ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }

}

我无法发布图片:(

4

1 回答 1

0

您必须添加DataGridView.CellValueChanged Event。当您更改任何单元格值时,将执行分配给该事件的函数。

// adding event handler (somewhere after dgvReports initialization)
dgvReports.CellValueChanged += new DataGridViewCellEventHandler(dgvReports_CellValueChanged);

// function that handles event
private void dgvReports_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    // `e` argument will contain e.RowIndex and e.ColumnIndex properties
    // they may be used to determine which particular cell was changed

}

在事件处理程序中,您应该检查更改了哪些列/单元格(行和单元格索引应该通过DataGridViewCellEventArgs e参数传递给处理CellValueChanged事件的方法)。

在那次检查之后 - 你应该“做你的更新”。

于 2013-03-03T13:49:36.577 回答