Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / February 2006

Tip: Looking for answers? Try searching our database.

Row provided already belongs to a DataGridView control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kh - 22 Feb 2006 16:40 GMT
Hi. I am adding a row to a DataGridView to provide "quick filter"
functionality (i.e. a row of combo boxes to allow easy filtering of column
values). If I am clearing rows from the grid I want to preserve the filter
row rather than recreate it. I use code similar to the following:

// filterRow is my DataGridViewRow containing combo boxe cells
dataGridView1.Rows.Clear();
dataGridView1.Rows.Add(filterRow);

However I get a "Row provided already belongs to a DataGridView control"
exception. How can I reuse this row? There is no public
DetachFromDataGridView() method defined on DataGridViewRow. I want to avoid
removing all other rows by index if possible.

Thanks

kh
"Wei-Dong XU [MS]" - 23 Feb 2006 08:46 GMT
Hi kh,

Thanks for posting.

Based on my understanding of your issue, you have implemented a row which
functionality similarly to Autofilter in EXCEL, then you can easily filter
the data. But when you clear the DGV and re-add the filterRow, a "Row
provided already belongs to a DataGridView control" exception is thrown. If
it is not correct, just feel free to tell me.

According to the description of the exception, it just because the
filterRow is not cleared from the DGV actually, then when you re-add it,
the exception was thrown. I have no idea of how it could happen, it seems
the clear method didn't work as you expected. And it is hard to tell what
factor cause the problem. To separate it, could you please send one sample
code to us reproducing how the problem happens, it is more possible for us
to locate the problem after the reproducing.

But as for you scene, I recommend please separate the filter functionality
outside the DGV, and use some list controls instead. These controls contain
every column's possible value. You can use a binding source to filter the
data, and the DGV use the binding source as its DataSource. The DGV doesn't
care whether the data is filtered or not, it just display the data provided
to.

Expect to your update! Thanks!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.
kh - 23 Feb 2006 17:27 GMT
Wei-Dong

Many thanks. Your assessment of my problem is correct, and unfortunately
what the users want the users get! As to why I am getting this exception I
can shed no more light. I create my filterRow object and hold a reference to
it, clear all rows and then re-add the filterRow. If I get a chance I will
distill this down to a simple demonstration of the problem.

kh

> Hi kh,
>
[quoted text clipped - 30 lines]
> ---------------------------------------------------------------------------
> It is my pleasure to be of any assistance.
"Wei-Dong XU [MS]" - 24 Feb 2006 09:35 GMT
Hi,

Thanks for the replying!

I have successfully reproduced your issue and currently we are researching
this for you. If any update, we will post back at the first time.

Have a nice weekend!

Best Regards,
Wei-Dong Xu
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
<https://partner.microsoft.com/US/technicalsupport/supportoverview/40010469>

Others: <https://partner.microsoft.com/US/technicalsupport/supportoverview/>
If you are outside the United States, please visit our International
Support page:
<http://support.microsoft.com/default.aspx?scid=%2finternational.aspx>.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
"Wei-Dong XU [MSFT]" - 27 Feb 2006 07:30 GMT
Hi,

Based on my research, the clear() method is not intended to be used
directly from developer's code.

Internally, the DataGridViewRow use a property called "DataGridView" to
indicate which container the row belongs to. It supposed to set the
[DataGridView] property to be null in the clear() method, but it keep the
value actually. So when you manually add the row to whatever DataGridView
again, in AddInternal() method, it will check the row's [DataGridView]
property first, and after it found the propery is not null, the container
think that the row is already belongs to another DataGridView, although
there is no DataGridView contains the row. Then the exception of "Row
provided already belongs to a DataGridView control" is thrown. From my
view, the cause is inside the clear() method, and unfortunately the
property [DataGridView] is read only. As I know, there is no way to change
it in our own code.

So currently, I'd suggest please use my workaround in the first reply for
this issue.

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.