all groups > dotnet windows forms databinding > july 2004 >
You're in the

dotnet windows forms databinding

group:

Binding to DataView.Count Bug?


Binding to DataView.Count Bug? JorgenD
7/7/2004 4:13:02 AM
dotnet windows forms databinding:
Hi.

When binding to the Count property of a DataView, the bound control is not updated when applying a rowfilter to the DataView.

Sample code:

dt = new DataTable();
dt.Columns.Add("Val",typeof(int));
DataRow row;

row = dt.NewRow();
row["Val"]=1;
dt.Rows.Add(row);

row = dt.NewRow();
row["Val"]=2;
dt.Rows.Add(row);

row = dt.NewRow();
row["Val"]=2;
dt.Rows.Add(row);

textBox1.DataBindings.Add("Text",dt.DefaultView.Count,"");

****** the TextBox shows "3"

dt.DefaultView.RowFilter="Val=1";

****** the TextBox STILL shows "3"

Is this a bug or am I doing something wrong?

Re: Binding to DataView.Count Bug? Jay B. Harlow [MVP - Outlook]
7/7/2004 9:40:54 AM
Jorgen,
My understanding is:

DataView does not have a CountChanged event, for the data bound TextBox to
update itself when DataView.Count property changes, the PropertyManager
listens for the DataView.CountChanged event, and update the TextBox
appropriately, well seeing as there is no CountChanged event, nothing
happens...

The above is assuming you bound to the Count property, not the value of
Count itself...

textBox1.DataBindings.Add("Text",dt.DefaultView,"Count");


[quoted text, click to view]
Also you are binding to a value type, it will be boxed, for ever breaking
the tie to the DataView itself...

Hope this helps
Jay

[quoted text, click to view]
alternative solutions!

AddThis Social Bookmark Button