1

I'm new developing and I need a detailed answered, I'm sorry for my bad english... I will try to explain myself the best I can.. I've 2 tables in Mysql

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

In my application I use all the information inside table1 to fill a DataGridView, also I've added a comboBox column, the combobox displays "status_name" from table2, I want to modify ticket_status with the information contained in the comboBox, how can I do that?

this is my code:

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());
        }

}

I'm not able to post Images :(

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 に答える