468,321 Members | 1,836 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

How do I refresh DataView filter efficiently

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();
Nov 17 '05 #1
3 10823
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]
- mv*@spam.guard.caspershouse.com

"Vern" <Ve**@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
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();

Nov 17 '05 #2
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]
- mv*@spam.guard.caspershouse.com

"Vern" <Ve**@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
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();


Nov 17 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Vern" <Ve**@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
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();


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by werk | last post: by
13 posts views Thread by Steve | last post: by
8 posts views Thread by KC | last post: by
4 posts views Thread by James | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.