Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm making a GUI for DATA entry. on the left side there is the data grid and on the right side there are textbox,combo box & wysiwyg editor. When clicked to one of the cells it will paste it to the right side where user able to edit anything what necessary. I made a "Save button" when it's clicked delete the text from the right side and update the data grid and update SQL with SQL adapter. However when the button pressed it does not save the changes to SQL, only after when I selected/clicked to another cell on the data grid and repressed the button. So probably I need to cancel the editing somehow?

My code is for the button:

private void button2_Click(object sender, EventArgs e)
{
    if (editor1.BodyHtml != null)
    {
        string edit_title = textBox2.Text.ToString();
        string edit_role = comboBox2.Text.ToString();
        string edit_desc = editor1.BodyHtml.ToString();
        int id = dataGridView1.CurrentCell.RowIndex;

        dataGridView1.CurrentRow.Cells[1].Value = edit_title;
        dataGridView1.CurrentRow.Cells[2].Value = edit_role;
        dataGridView1.CurrentRow.Cells[3].Value = edit_desc;

        dataGridView1.UpdateCellValue(1, id);
        dataGridView1.UpdateCellValue(2, id);
        dataGridView1.UpdateCellValue(3, id);

        textBox2.ResetText();
        comboBox2.ResetText();
        editor1.Clear();
        dataGridView1.Refresh();

    }

    try
    {
        cmdbl = new SqlCommandBuilder(adap);
        adap.Update(ds, "CreatedJobs");
        MessageBox.Show("Job has been Updated!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }



}
Posted
Comments
George Jonsson 25-Nov-15 20:00pm    
Have you tried dataGridView1.EndEdit() ?
[no name] 25-Nov-15 22:38pm    
yep. Tried a few things as I first went through google.
Sinisa Hajnal 26-Nov-15 3:56am    
How about you update ds directly instead of grid cells, call adap.Update and then refresh the grid?
You can get datasource row item with (DataRowView)dgv.CurrentRow.DataBoundItem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900