CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    3

    [RESOLVED] Cannot update values to multiple rows i dataGridView

    Hi,

    I am using Visual Studio 2010 RC, but I don't know if this problem is unique for this version of Visual Studio.

    I am trying to update two values of the selected rows in a dataGridView. I've set the multiselect property to true and the selection mode property to FullRowSelect. When I select a number of rows in the DGV and click the button that fires the updating event the top most row does not get updated. But the other rows do.

    Here is the method that updates the rows:

    private void buttonOverfoering_Click(object sender, EventArgs e)
    {
    foreach (DataGridViewRow dr in bestillingerDataGridView.SelectedRows)
    {
    dr.Cells[9].Value = "Bestilt";
    dr.Cells[10].Value = DateTime.Now;
    }
    this.bestillingerTableAdapter.Update(this.bestillingerDataSet.Bestillinger);
    }

    I don't know if this is the best or right way to update values in a DGV and save them back to the database. It certainly is easy, had it only worked...

  2. #2
    Join Date
    Feb 2010
    Posts
    3

    Re: Cannot update values to multiple rows i dataGridView

    I also tried with this:

    foreach (DataGridViewRow dr in bestillingerDataGridView.Rows)
    {
    if (dr.Selected)
    {
    dr.Cells[9].Value = "Bestilt";
    dr.Cells[10].Value = DateTime.Now;
    }
    }
    this.bestillingerTableAdapter.Update(this.bestillingerDataSet.Bestillinger);

    Now it only updates one out of three rows!?

  3. #3
    Join Date
    Feb 2010
    Posts
    3

    Re: [RESOLVED] Cannot update values to multiple rows i dataGridView

    I solved it with a custom update query in my dataset instead.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured