RowFilter property of a dataview

  • Thread starter Thread starter EMW
  • Start date Start date
E

EMW

If I have a column of dates, how can I set the rowfilter to filter those
rows out that are from a specific year.

I've tried several possibilities as LIKE , but nothing does it.
I've googled it, but I'm still in the dark.

anyone, please?

rg,
Eric
 
Hi,

Yes, it is a pain.
I suggest you to add a boolean column to your datatable, and set its values
accordingly to whether it is filtered or not (you create the condition
manually).
Then filter on that column.
Remember, though, that such action will set rows and datatable state to
changed.
You might invoke AcceptChanges to consolidate the state.
 
I found out the following and it works too:

If you do RowFilter = "name = 'someone'" it will filter on all the names;
name is a columnname.
if you also want to add another column to filter in: use AND
i.e. RowFilter = "name = 'someone' AND address= 'somewhere'"

if you want to select on a date: you could do it like this:

Row filter = "(mydate >= '01-01-2004' AND mydate <= '31-12-2004')"
if will then filter column mydate to only show the rows where the date is in
the year 2004.
Ofcourse you can modify the date to be more specific.

If you want to filter the rows on which the cell of a column is not empty
then use this:

RowFilter = "IsNull(name,'')<>''" (Only the last and first quotes are
double ones, the rest are single)

I believe IsDate is also possible.


Hope I help someone with this.

rg,
Eric






David Clegg said:
Another suggestion...
If you do find a solution to your problem, post it here so others may
benefit.

--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com
http://cc.borland.com/codecentral/ccweb.exe/author?authorid=72299

Quality Central. The best way to bug Borland about bugs.
http://qc.borland.com

"Without TV, it is hard to know when one day ends and another
begins." - Homer Simpson


Miha Markic said:
Hi,

Yes, it is a pain.
I suggest you to add a boolean column to your datatable, and set its values
accordingly to whether it is filtered or not (you create the condition
manually).
Then filter on that column.
Remember, though, that such action will set rows and datatable state to
changed.
You might invoke AcceptChanges to consolidate the state.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


EMW said:
If I have a column of dates, how can I set the rowfilter to filter those
rows out that are from a specific year.

I've tried several possibilities as LIKE , but nothing does it.
I've googled it, but I'm still in the dark.

anyone, please?

rg,
Eric
 
Yes, a good solution not as much flexible as my, but good enough with one
exception:
Your solution won't work when Thread is running in different culture
(Regional settings perhaps), for example on en-US settings, where date is
defined as
MM/dd/yyyy.
The correct way would be to define date as #MM/dd/yyyy# => #1/1/2004# and
#12/31/2004# in your case.
When defined in this way they are culture independent I believe.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


EMW said:
I found out the following and it works too:

If you do RowFilter = "name = 'someone'" it will filter on all the names;
name is a columnname.
if you also want to add another column to filter in: use AND
i.e. RowFilter = "name = 'someone' AND address= 'somewhere'"

if you want to select on a date: you could do it like this:

Row filter = "(mydate >= '01-01-2004' AND mydate <= '31-12-2004')"
if will then filter column mydate to only show the rows where the date is in
the year 2004.
Ofcourse you can modify the date to be more specific.

If you want to filter the rows on which the cell of a column is not empty
then use this:

RowFilter = "IsNull(name,'')<>''" (Only the last and first quotes are
double ones, the rest are single)

I believe IsDate is also possible.


Hope I help someone with this.

rg,
Eric






David Clegg said:
Another suggestion...
If you do find a solution to your problem, post it here so others may
benefit.

--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com
http://cc.borland.com/codecentral/ccweb.exe/author?authorid=72299

Quality Central. The best way to bug Borland about bugs.
http://qc.borland.com

"Without TV, it is hard to know when one day ends and another
begins." - Homer Simpson


Miha Markic said:
Hi,

Yes, it is a pain.
I suggest you to add a boolean column to your datatable, and set its values
accordingly to whether it is filtered or not (you create the condition
manually).
Then filter on that column.
Remember, though, that such action will set rows and datatable state to
changed.
You might invoke AcceptChanges to consolidate the state.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


EMW said:
If I have a column of dates, how can I set the rowfilter to filter those
rows out that are from a specific year.

I've tried several possibilities as LIKE , but nothing does it.
I've googled it, but I'm still in the dark.

anyone, please?

rg,
Eric
 
Back
Top