0

I'm trying to create an Update button to let me insert data into a gridview and after creating the class, the button does nothing and I don't understand why that is the case.

private void Basic()
{
    // no updates allowed
    dataGridView1.AllowUserToAddRows = false;
    dataGridView1.AllowUserToDeleteRows = false;
    dataGridView1.ReadOnly = true;

    //UpdateButton is available

    UpdateButton.Enabled = true;

    //Save and Cancel Unavailable

    SaveButton.Visible = false;
    CancelButton.Visible = false;

    sTableAdapter.Fill(dataSet1.S);
}

This is the UpdateButton Event

private void UpdateButton_Click(Object sender, EventArgs e)
{
    dataGridView1.AllowUserToAddRows = true;
    dataGridView1.AllowUserToDeleteRows = true;
    dataGridView1.ReadOnly = false;

    UpdateButton.Enabled = false;

    SaveButton.Visible = true;
    CancelButton.Visible = true;
}

And this should be the update class:

this.UpdateButton.Location = new System.Drawing.Point(12, 63);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(103, 23);
this.UpdateButton.TabIndex = 0;
this.UpdateButton.Text = "Update";
this.UpdateButton.UseVisualStyleBackColor = true;

The connection is made with a accdb. The Update button isn't working on click, what did I do wrong?

Paul Karam
  • 4,052
  • 8
  • 30
  • 53
Schneejäger
  • 231
  • 3
  • 15
  • Well this is not an update button `class`, it is the button click `event handler`... The second thing - what is your exact question? – pitersmx Jun 13 '17 at 10:51
  • Can you debug click event of update button? – Chetan Jun 13 '17 at 10:51
  • Hmmm… where is the code for the `UpdateButton_Click` event? Without this event… as you said… _"the button does nothing"_ – JohnG Jun 13 '17 at 11:05
  • How should I add it? – Schneejäger Jun 13 '17 at 11:06
  • Double click on the button in design view and it will create it for you. – JohnG Jun 13 '17 at 11:07
  • I have one there but it doesn't do anything, will post it – Schneejäger Jun 13 '17 at 11:09
  • There is nothing in the click event code that updates the `DataGridView`, `DataTable` or the “database” with new data. The code appears to simply allow the user to add new rows of data to the `DataGridView`. What were you expecting it to do? – JohnG Jun 13 '17 at 11:22
  • I was expecting it to let me add rows and then with another button save the changes into the DB. Kind of an add button actually. – Schneejäger Jun 13 '17 at 11:23
  • After you click the update button, this does not happen? Is there a new blank row at the bottom of the `DataGridView` after you click this update button? – JohnG Jun 13 '17 at 11:28
  • No, nothing happens, it's a blank click, no new row. – Schneejäger Jun 13 '17 at 11:29
  • Found the solution, after double-clicking and creating another UpdateButton_Click_1 (that's the name it gave itself) and introduced the code from UpdateButton_Click inside it worked. – Schneejäger Jun 13 '17 at 11:32
  • That will do it – JohnG Jun 13 '17 at 11:32
  • __Do not__ call a `DataGridView`a `GridView` or a `DataGrid` and vice versa!! This is wrong and confusing as those are different controls. - You should study this post on [hooking up events] (http://stackoverflow.com/questions/33275763/copy-datagridview-values-to-textbox/33276161?s=14|0.0000#33276161) – TaW Jun 13 '17 at 12:36

0 Answers0