dcsimg
Results 1 to 4 of 4

Thread: Rows collection cannot be programmatically cleared -- Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    12

    Rows collection cannot be programmatically cleared -- Error

    Hello All ......


    I Have Bound DataGridView and i tried to clear it before get record ihave tried :

    Code:
    DGV.Rows.Clear

    And

    Code:
    DGV.Datasorce=Nothing
    And

    Code:
    dt.clear

    None Or Then Works iand iam getting this error


    Rows collection cannot be programmatically cleared when the DataGridView control is data-bound to anything else than an IBindingList that supports change notification and allows deletion.


    Name:  error.jpg
Views: 179
Size:  23.3 KB
    Last edited by Salem141; Feb 20th, 2018 at 09:02 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,772

    Re: Rows collection cannot be programmatically cleared -- Error

    Right... so as long as it is bound, you cannot clear the rows. So you have to do two things. Unbind the DGV, then clear the rows.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    12

    Re: Rows collection cannot be programmatically cleared -- Error

    Got it ...

    Code:
                DGV.DataSource = Nothing
                DGV.Rows.Clear()
    Thanks For Help

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,776

    Re: Rows collection cannot be programmatically cleared -- Error

    If you set the DataSource to Nothing then that should remove the rows automatically. The question is whether setting the DataSource to Nothing is the correct option. It may actually be more appropriate that the grid remains bound and you remove/delete all the rows/items in the data source. We can't really say based on the information provided. Looking at your screenshot though, it looks like you're doing something weird. Why are you adding rows to the grid directly from a DataTable? Why aren't you simply binding that DataTable to the grid?
    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

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
  •  



Featured


Click Here to Expand Forum to Full Width