Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Refreshing DataGridView

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [RESOLVED] [2005] Refreshing DataGridView

    How can i refresh the DGV to clear all values in it first and then update itself from the database containing current values?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Refreshing DataGridView

    Use databinding. To clear, you set the DataSource property of your DGV to Nothing. To display new data, you query your database for whatever data you need then set the datasource property to the of the DGV to that data.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Refreshing DataGridView

    You shouldn't be setting the DataSource of the grid to Nothing. If the grid is bound to a DataTable then leave it bound to that DataTable. You simply Fill that DataTable using a DataAdapter or TableAdapter and the bound grid will display the new contents. If you need to Clear the DataTable first then do so.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Refreshing DataGridView

    How can i Clear the datatable (DataGridView) ?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Refreshing DataGridView

    When you read the MSDN documentation for the DataTable class you must have missed the Clear method. You'll have to look more carefully when reading the MSDN documentation in the future, won't you?

    Note that if you're using a TableAdapter to Fill the DataTable then it will implicitly call the table's Clear method for you, assuming that its ClearBeforeFill property (or a similar name) is set to True, which I think it is by default.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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