Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bitwise operators in RowFilter

320 views
Skip to first unread message

Paul S

unread,
Feb 28, 2008, 5:25:00 AM2/28/08
to

I want to set the DataSourse of a ComboBox and for that a have a DataTable
containing the data.
I only want a subset of the data bound to my ComboBox so I create a DataView
and try to select
the data using a RowFilter. The table has a numeric column on which I want
to base my selection using
bitwise operation like

NumVal & 2 <> 0

to check if the second bit is set, but the Rowfilter does not like the '&'.
Then I thought that I
could extend my select with

select .., NumVal & 2 as x

and then change my Rowfilter to

xx <> 0

but I can only see the DataView is created based on the columns in the table.

How can I solved my problem ?
--
Thanks
Paul S

Linda Liu[MSFT]

unread,
Feb 28, 2008, 9:51:46 PM2/28/08
to
Hi Paul,

The expression used to filter rows doesn't support the bitwise operator '&'
so far. It only supports the following arithmetic operators:

+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulus)

We can get what you want using the following expression:

Convert((ID - ID %2)/2,'System.Int32') % 2 = 1

So setting this expression to the RowFilter property of the DataView as
follows should solve your problem:

DataTable table= new DataTable();
DataView view = new DataView(table);
view.RowFilter = "Convert((ID - ID %2)/2,'System.Int32') % 2 = 1";

For more information on column expression, please refer to the following
MSDN document:

http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.a
spx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Paul S

unread,
Feb 29, 2008, 3:29:01 AM2/29/08
to
Hi Linda
Sorry I didn't make it clear that I want to be able to select on any bit -
not just the second bit.

- can that be solved ?
--
Paul S

Linda Liu[MSFT]

unread,
Feb 29, 2008, 4:29:01 AM2/29/08
to
Hi Paul,

Thank you for your prompt response!

It's no problem to select on any bit. For example, to select the third bit,
the filter string should be like the following:

Convert((ID - ID %4)/4,'System.Int32') % 2 = 1

and to select the fourth bit, the filter string should be:

Convert((ID - ID %8)/8,'System.Int32') % 2 = 1

and to select the fifth bit, the filter string should be:

Convert((ID - ID %16)/16,'System.Int32') % 2 = 1

Paul S

unread,
Feb 29, 2008, 1:09:12 PM2/29/08
to

Thanks
I see that it solves my problem

--
Paul S

0 new messages