PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

How do I refresh DataView filter efficiently

 
 
=?Utf-8?B?VmVybg==?=
Guest
Posts: n/a
 
      7th Sep 2005
The following code retrieves data into a dataset, and then creates a dataview
with a filter. This dataview is then attached to a combobox. When the
effective date changes, I would like to see the newly filtered data without
having to create a new dataview each time. Is that possible?
Also, do I need to attach the dataview to the combo box each time?

if (AgencyCounties == null || sPropertyState.Text != prevPropertyState)
{
AgencyCounties = Producer.GetAgencyCounties(Producer.AgencyId,
sPropertyState.Text,"11");

AgencyCounties.Tables["Table"].TableName = "AgencyCounty";
prevPropertyState = sPropertyState.Text;
}

sPropertyCountyCd.BeginUpdate();

DataView viewCounties = new DataView(AgencyCounties.Tables["AgencyCounty"]);

string Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is Null
OR StopDt > '" + sEffectiveDt.Text + "')";

viewCounties.RowFilter = Filter;

sPropertyCountyCd.DisplayMember = "Name";
sPropertyCountyCd.ValueMember = "CountyCd";
sPropertyCountyCd.DataSource = viewCounties;
sPropertyCountyCd.EndUpdate();
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      7th Sep 2005
Vern,

You should be able to set the Filter of the view that the list is bound
to, and it should change the list automatically when the filter is set.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Vern" <(E-Mail Removed)> wrote in message
news:F6D989D0-85F1-4315-BD9B-(E-Mail Removed)...
> The following code retrieves data into a dataset, and then creates a
> dataview
> with a filter. This dataview is then attached to a combobox. When the
> effective date changes, I would like to see the newly filtered data
> without
> having to create a new dataview each time. Is that possible?
> Also, do I need to attach the dataview to the combo box each time?
>
> if (AgencyCounties == null || sPropertyState.Text != prevPropertyState)
> {
> AgencyCounties = Producer.GetAgencyCounties(Producer.AgencyId,
> sPropertyState.Text,"11");
>
> AgencyCounties.Tables["Table"].TableName = "AgencyCounty";
> prevPropertyState = sPropertyState.Text;
> }
>
> sPropertyCountyCd.BeginUpdate();
>
> DataView viewCounties = new
> DataView(AgencyCounties.Tables["AgencyCounty"]);
>
> string Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is
> Null
> OR StopDt > '" + sEffectiveDt.Text + "')";
>
> viewCounties.RowFilter = Filter;
>
> sPropertyCountyCd.DisplayMember = "Name";
> sPropertyCountyCd.ValueMember = "CountyCd";
> sPropertyCountyCd.DataSource = viewCounties;
> sPropertyCountyCd.EndUpdate();



 
Reply With Quote
 
=?Utf-8?B?VmVybg==?=
Guest
Posts: n/a
 
      8th Sep 2005
I changed it to this, and it doesn't change what the combobox is showing.
Debug shows it executing "viewCounties.RowFilter = Filter" but the drop down
list doesn't change. What am I doing wrong?

// Refresh the Dataset if the Property State changes
if (AgencyCounties == null || sPropertyState.Text != prevPropertyState)
{
AgencyCounties = Producer.GetAgencyCounties(Producer.AgencyId,
sPropertyState.Text,"11");
AgencyCounties.Tables["Table"].TableName = "AgencyCounty";
prevPropertyState = sPropertyState.Text;
}



if (viewCounties == null)
{
sPropertyCountyCd.BeginUpdate();
viewCounties = new DataView(AgencyCounties.Tables["AgencyCounty"]);
Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is Null OR
StopDt > '" + sEffectiveDt.Text + "')";
viewCounties.RowFilter = Filter;
sPropertyCountyCd.DisplayMember = "Name";
sPropertyCountyCd.ValueMember = "CountyCd";
sPropertyCountyCd.DataSource = viewCounties;
sPropertyCountyCd.EndUpdate();
}
else
{
viewCounties.RowFilter = Filter;
}

"Nicholas Paldino [.NET/C# MVP]" wrote:

> Vern,
>
> You should be able to set the Filter of the view that the list is bound
> to, and it should change the list automatically when the filter is set.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Vern" <(E-Mail Removed)> wrote in message
> news:F6D989D0-85F1-4315-BD9B-(E-Mail Removed)...
> > The following code retrieves data into a dataset, and then creates a
> > dataview
> > with a filter. This dataview is then attached to a combobox. When the
> > effective date changes, I would like to see the newly filtered data
> > without
> > having to create a new dataview each time. Is that possible?
> > Also, do I need to attach the dataview to the combo box each time?
> >
> > if (AgencyCounties == null || sPropertyState.Text != prevPropertyState)
> > {
> > AgencyCounties = Producer.GetAgencyCounties(Producer.AgencyId,
> > sPropertyState.Text,"11");
> >
> > AgencyCounties.Tables["Table"].TableName = "AgencyCounty";
> > prevPropertyState = sPropertyState.Text;
> > }
> >
> > sPropertyCountyCd.BeginUpdate();
> >
> > DataView viewCounties = new
> > DataView(AgencyCounties.Tables["AgencyCounty"]);
> >
> > string Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is
> > Null
> > OR StopDt > '" + sEffectiveDt.Text + "')";
> >
> > viewCounties.RowFilter = Filter;
> >
> > sPropertyCountyCd.DisplayMember = "Name";
> > sPropertyCountyCd.ValueMember = "CountyCd";
> > sPropertyCountyCd.DataSource = viewCounties;
> > sPropertyCountyCd.EndUpdate();

>
>
>

 
Reply With Quote
 
=?Utf-8?B?VmVybg==?=
Guest
Posts: n/a
 
      8th Sep 2005
Never mind. I just realized my mistake. I wasn't changing the filter string.
The else should have been as follows:
else
{
Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is Null OR
StopDt > '" + sEffectiveDt.Text + "')";
viewCounties.RowFilter = Filter;
}

"Vern" wrote:

> I changed it to this, and it doesn't change what the combobox is showing.
> Debug shows it executing "viewCounties.RowFilter = Filter" but the drop down
> list doesn't change. What am I doing wrong?
>
> // Refresh the Dataset if the Property State changes
> if (AgencyCounties == null || sPropertyState.Text != prevPropertyState)
> {
> AgencyCounties = Producer.GetAgencyCounties(Producer.AgencyId,
> sPropertyState.Text,"11");
> AgencyCounties.Tables["Table"].TableName = "AgencyCounty";
> prevPropertyState = sPropertyState.Text;
> }
>
>
>
> if (viewCounties == null)
> {
> sPropertyCountyCd.BeginUpdate();
> viewCounties = new DataView(AgencyCounties.Tables["AgencyCounty"]);
> Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is Null OR
> StopDt > '" + sEffectiveDt.Text + "')";
> viewCounties.RowFilter = Filter;
> sPropertyCountyCd.DisplayMember = "Name";
> sPropertyCountyCd.ValueMember = "CountyCd";
> sPropertyCountyCd.DataSource = viewCounties;
> sPropertyCountyCd.EndUpdate();
> }
> else
> {
> viewCounties.RowFilter = Filter;
> }
>
> "Nicholas Paldino [.NET/C# MVP]" wrote:
>
> > Vern,
> >
> > You should be able to set the Filter of the view that the list is bound
> > to, and it should change the list automatically when the filter is set.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - (E-Mail Removed)
> >
> > "Vern" <(E-Mail Removed)> wrote in message
> > news:F6D989D0-85F1-4315-BD9B-(E-Mail Removed)...
> > > The following code retrieves data into a dataset, and then creates a
> > > dataview
> > > with a filter. This dataview is then attached to a combobox. When the
> > > effective date changes, I would like to see the newly filtered data
> > > without
> > > having to create a new dataview each time. Is that possible?
> > > Also, do I need to attach the dataview to the combo box each time?
> > >
> > > if (AgencyCounties == null || sPropertyState.Text != prevPropertyState)
> > > {
> > > AgencyCounties = Producer.GetAgencyCounties(Producer.AgencyId,
> > > sPropertyState.Text,"11");
> > >
> > > AgencyCounties.Tables["Table"].TableName = "AgencyCounty";
> > > prevPropertyState = sPropertyState.Text;
> > > }
> > >
> > > sPropertyCountyCd.BeginUpdate();
> > >
> > > DataView viewCounties = new
> > > DataView(AgencyCounties.Tables["AgencyCounty"]);
> > >
> > > string Filter = "StartDt <= '" + sEffectiveDt.Text + "' AND (StopDt is
> > > Null
> > > OR StopDt > '" + sEffectiveDt.Text + "')";
> > >
> > > viewCounties.RowFilter = Filter;
> > >
> > > sPropertyCountyCd.DisplayMember = "Name";
> > > sPropertyCountyCd.ValueMember = "CountyCd";
> > > sPropertyCountyCd.DataSource = viewCounties;
> > > sPropertyCountyCd.EndUpdate();

> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: DataView filter Marina Levit [MVP] Microsoft ASP .NET 2 22nd Dec 2006 03:44 PM
HELP: DataView does NOT filter :-( werk@velp.info Microsoft C# .NET 1 20th Jan 2005 04:13 PM
Re: Filter DataView William Ryan eMVP Microsoft C# .NET 0 6th May 2004 04:36 PM
Dataview Refresh? Mike Cooper Microsoft ADO .NET 1 15th Mar 2004 09:32 PM
How do I refresh the DataView Lord2702 Microsoft ADO .NET 0 22nd Jul 2003 07:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:24 PM.