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 Data Binding / October 2005

Tip: Looking for answers? Try searching our database.

Using DataView filter when binding to DataGridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tab - 19 Oct 2005 10:02 GMT
I have set the 'datasource' property of a 'bindingsource' object to a
DataView ('dv').  The dv is in turn bound to a dataset table:

           dv = this.MyDataSet.MyTable.DefaultView;

I then set the 'datasource' property of a DataGridView ('DGV') object to the
'bindingsource' object.

The DGV has a 'DataGridViewCheckBoxColumn' (true value=1, false value =0)..

Finally, I set the RowFilter of the dv (in the form constructor) as follows:

           dv.RowFilter = "Completed = '0'";

When running the project in Visual Studio 2005, the DGV displays rows with
the checkbox column all clear (i.e. unticked).  The first click on the
checkbox column of a row does nothing, but another click on a different row
causes the first clicked row to disappear (the dv filter kicks in).

I will be grateful for any clues as to why the first click does not invoke
the filter.

Thanks
Bart Mermuys - 19 Oct 2005 16:23 GMT
Hi,

>I have set the 'datasource' property of a 'bindingsource' object to a
> DataView ('dv').  The dv is in turn bound to a dataset table:
[quoted text clipped - 21 lines]
> I will be grateful for any clues as to why the first click does not invoke
> the filter.

When you change a cell inside a row then the DataRow enters edit mode
(BeginEdit) and the changes can be reverted  by pressing Escape (CancelEdit)
or accepted by moving to another row (EndEdit).  It's only when they are
accepted that the rowfilter kicks in.

hth,
Greetings

> Thanks
tab - 19 Oct 2005 19:20 GMT
Thanks Bart,

However, if you set up a simple test application to mimic the scenario in my
original post i.e.

- A Database table with 3 rows with an ID column and a 'completed' column
with    
  values 'N'

- The 'completed' column  hooked to a DataGridView CheckBox column via a
   DataView

- The DataView filtered to only show completed='N'

you should find the following behaviour:

Click the checkbox cell in the first row (starting index 0) to change the
value to true  ( Event: BeginEdit for first row)

Click third row (starting index 2) - we get an IndexOutofRangeException:
Index 2 does not have a value

What seems to be happening is that when the RowFilter kicks in (presumably
on EndEdit for first row), the third row's index becomes 1 (as only 2 rows
left) but somewhere in the system the index value for  the third row is still
at 2 and has not been updated.

Similar errors occur with more rows and different sequences of clicks.

Is this a bug or am I not handling some event somewhere?

I hope the above makes sense.

Thanks

> Hi,
>
[quoted text clipped - 33 lines]
>
> > Thanks
Bart Mermuys - 19 Oct 2005 20:33 GMT
Hi,
> Thanks Bart,
>
[quoted text clipped - 28 lines]
>
> Is this a bug or am I not handling some event somewhere?

I tried the setup you describe and i get a NullReferenceException when i
repeat the steps twice. I suspect this is a bug, it doesn't happen with a
DataGrid in vs2003.  The latest version i tried is vs2005b2, hopefully it's
fixed in the final release.

Greetings

> I hope the above makes sense.
>
[quoted text clipped - 41 lines]
>>
>> > Thanks
tab - 19 Oct 2005 20:49 GMT
Bart,

I really appreciate your help - thank you.

I think I''ll take the unbound route.......

> Hi,
> > Thanks Bart,
[quoted text clipped - 82 lines]
> >>
> >> > Thanks

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.