Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Datagridview not refreshing

Datagridview not refreshing

Scheduled Pinned Locked Moved Visual Basic
helpquestioncssannouncement
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rey9999
    wrote on last edited by
    #1

    Hello Everyone. I hope someone can help me with this problem. i have a datatable bound to a bindingsource, and i display its content through a datagridview in this way: bindingSource1.DataSource = dataTable1 dataGridView1.DataSource = bindingSource1 My problem is that when i update the data contained in the table through the bindingsource, my datagridview does not refresh and keeps displaying the old values. but the strangest thing is that if i manually sort the datagridview by clicking a column header, the datagrid refreshes and displays the updated values. this occurs only if i manually click on the headers, it does not work if i sort the grid in the code or if i call datagridview1.refresh() I desperately need the datagrid to update its values as i update the bindingsource, without clicking anything. how can i do that? Thanks in Advance, Rey9999

    ~~~ From Milano to The Hague, easy as it goes ~~~

    S 1 Reply Last reply
    0
    • R Rey9999

      Hello Everyone. I hope someone can help me with this problem. i have a datatable bound to a bindingsource, and i display its content through a datagridview in this way: bindingSource1.DataSource = dataTable1 dataGridView1.DataSource = bindingSource1 My problem is that when i update the data contained in the table through the bindingsource, my datagridview does not refresh and keeps displaying the old values. but the strangest thing is that if i manually sort the datagridview by clicking a column header, the datagrid refreshes and displays the updated values. this occurs only if i manually click on the headers, it does not work if i sort the grid in the code or if i call datagridview1.refresh() I desperately need the datagrid to update its values as i update the bindingsource, without clicking anything. how can i do that? Thanks in Advance, Rey9999

      ~~~ From Milano to The Hague, easy as it goes ~~~

      S Offline
      S Offline
      Sebrell
      wrote on last edited by
      #2

      Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.

      R 1 Reply Last reply
      0
      • S Sebrell

        Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.

        R Offline
        R Offline
        Rey9999
        wrote on last edited by
        #3

        Sebrell wrote:

        Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.

        i tried but i still have the same problem...

        ~~~ From Milano to The Hague, easy as it goes ~~~

        S 1 Reply Last reply
        0
        • R Rey9999

          Sebrell wrote:

          Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.

          i tried but i still have the same problem...

          ~~~ From Milano to The Hague, easy as it goes ~~~

          S Offline
          S Offline
          Sebrell
          wrote on last edited by
          #4

          so much for the simple answer... I'm reminded of a similar problem I once had with a RichTextBox, where I needed to force it to redraw its scroll-bars. I solved that problem by writing a method along the lines of the following: (C# code, sorry) private void Jiggle() { if (this.Orientation == Orientation.Horizontal) { this.rtfBox.Width -= 3; this.rtfBox.Width += 3; } else { this.rtfBox.Height -= 3; this.rtfBox.Height += 3; } this.rtfBox.Invalidate(); } I then called this method from the method that needed to redraw the RichTextBox (which was a property setter for a container control). I was surprised how well it worked. Especially since the RichTextBox in question had its Dock property set to DockStyle.Fill. I'd suggest dynamically changing, by a small number of pixels (fewer than 8), the Width of one of the ColumnHeaders in your DataGridView, since it works when you click it. Or to change the Sort column to a different column, then back to the original column. HTH Sebrell -- modified at 14:30 Wednesday 18th October, 2006

          R 1 Reply Last reply
          0
          • S Sebrell

            so much for the simple answer... I'm reminded of a similar problem I once had with a RichTextBox, where I needed to force it to redraw its scroll-bars. I solved that problem by writing a method along the lines of the following: (C# code, sorry) private void Jiggle() { if (this.Orientation == Orientation.Horizontal) { this.rtfBox.Width -= 3; this.rtfBox.Width += 3; } else { this.rtfBox.Height -= 3; this.rtfBox.Height += 3; } this.rtfBox.Invalidate(); } I then called this method from the method that needed to redraw the RichTextBox (which was a property setter for a container control). I was surprised how well it worked. Especially since the RichTextBox in question had its Dock property set to DockStyle.Fill. I'd suggest dynamically changing, by a small number of pixels (fewer than 8), the Width of one of the ColumnHeaders in your DataGridView, since it works when you click it. Or to change the Sort column to a different column, then back to the original column. HTH Sebrell -- modified at 14:30 Wednesday 18th October, 2006

            R Offline
            R Offline
            Rey9999
            wrote on last edited by
            #5

            i'll try, thanks

            ~~~ From Milano to The Hague, easy as it goes ~~~

            R 1 Reply Last reply
            0
            • R Rey9999

              i'll try, thanks

              ~~~ From Milano to The Hague, easy as it goes ~~~

              R Offline
              R Offline
              Rey9999
              wrote on last edited by
              #6

              I found the solution by chance... i realized i was updating the bindingsource's datasource instead of the bindingsource itself. may i be cursed eternally for my mistake ;)

              ~~~ From Milano to The Hague, easy as it goes ~~~

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups