473,671 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bitmask Databing

TD
Is there a way to DataBind controls to a specific Bit in Bitmask? Here is
some sample code of what I am trying to do ... I am trying to bind the
Visible and Enabled properties of a Button to specific bits in a Bitmask
stored in a DataTable.

namespace Test

{

[Flags]

public enum ButtonStateEnum

{

Enabled = 0x001,

Visible = 0x002,

}

public partial class Form1 : Form

{

public Form1()

{

InitializeCompo nent();

}

private void Form1_Load(obje ct sender, EventArgs e)

{

// Boolean bValue = true;

ButtonStateEnum bValue = ButtonStateEnum .Enabled | ButtonStateEnum .Visible;

DataTable dt = new DataTable();

dt.Columns.Add( "Flags", typeof(ButtonSt ateEnum));

dt.Rows.Add(bVa lue);

buttonBound.Dat aBindings.Add(" Enabled", dt, "Flags" );

buttonBound.Dat aBindings.Add(" Visible", dt, "Flags");

}

}

}
Aug 20 '07 #1
3 3676
TD,

No, you can't do this directly. I would create an adapter class, which
takes the bitmask and then has a number of boolean properties, one for each
bit in the mask. Then, you can set/get the values, and then have a property
which is the value of the assemblied bitmask.

You can have to implement the INotifyProperty Changed interface, and fire
the PropertyChanged event any time any of the values change.

You then should be able to bind to an instance of that adapter.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"TD" <so*****@somewh ere.comwrote in message
news:Of******** ******@TK2MSFTN GP02.phx.gbl...
Is there a way to DataBind controls to a specific Bit in Bitmask? Here is
some sample code of what I am trying to do ... I am trying to bind the
Visible and Enabled properties of a Button to specific bits in a Bitmask
stored in a DataTable.

namespace Test

{

[Flags]

public enum ButtonStateEnum

{

Enabled = 0x001,

Visible = 0x002,

}

public partial class Form1 : Form

{

public Form1()

{

InitializeCompo nent();

}

private void Form1_Load(obje ct sender, EventArgs e)

{

// Boolean bValue = true;

ButtonStateEnum bValue = ButtonStateEnum .Enabled |
ButtonStateEnum .Visible;

DataTable dt = new DataTable();

dt.Columns.Add( "Flags", typeof(ButtonSt ateEnum));

dt.Rows.Add(bVa lue);

buttonBound.Dat aBindings.Add(" Enabled", dt, "Flags" );

buttonBound.Dat aBindings.Add(" Visible", dt, "Flags");

}

}

}


Aug 20 '07 #2
TD
Without posting a bunch of code from my class that implements
INotifyProperty Changed which is ButtonStateValu e, I still don't see how to
be able to bind this to the individual properties inside a DataSet ... or am
I going about this the wrong way?

ButtonStateValu e bValue = new ButtonStateValu e();

bValue.ButtonSt ate = ButtonStateEnum .Enabled | ButtonStateEnum .Visible;

DataTable dt = new DataTable();

dt.Columns.Add( "Flags", typeof(ButtonSt ateValue));

dt.Rows.Add(bVa lue);

buttonBound.Dat aBindings.Add(" Enabled", dt, "Flags" );

buttonBound.Dat aBindings.Add(" Visible", dt, "Flags");

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
TD,

No, you can't do this directly. I would create an adapter class, which
takes the bitmask and then has a number of boolean properties, one for
each bit in the mask. Then, you can set/get the values, and then have a
property which is the value of the assemblied bitmask.

You can have to implement the INotifyProperty Changed interface, and
fire the PropertyChanged event any time any of the values change.

You then should be able to bind to an instance of that adapter.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"TD" <so*****@somewh ere.comwrote in message
news:Of******** ******@TK2MSFTN GP02.phx.gbl...
>Is there a way to DataBind controls to a specific Bit in Bitmask? Here is
some sample code of what I am trying to do ... I am trying to bind the
Visible and Enabled properties of a Button to specific bits in a Bitmask
stored in a DataTable.

namespace Test

{

[Flags]

public enum ButtonStateEnum

{

Enabled = 0x001,

Visible = 0x002,

}

public partial class Form1 : Form

{

public Form1()

{

InitializeComp onent();

}

private void Form1_Load(obje ct sender, EventArgs e)

{

// Boolean bValue = true;

ButtonStateEnu m bValue = ButtonStateEnum .Enabled |
ButtonStateEnu m.Visible;

DataTable dt = new DataTable();

dt.Columns.Add ("Flags", typeof(ButtonSt ateEnum));

dt.Rows.Add(bV alue);

buttonBound.Da taBindings.Add( "Enabled", dt, "Flags" );

buttonBound.Da taBindings.Add( "Visible", dt, "Flags");

}

}

}



Aug 20 '07 #3
You aren't going to be able to bind it to the data set. The
INotifyProperty Changed interface is only going to allow your grid to bind to
that class, and know when changes are made (through the setting of the
flags).

If you want to bind the property that exposes the bitmask to a field in
a data set, then you are going to have to implement the IBindableCompon ent
interface (it's not too hard). Once you do that, and then you should be
able to bind the data grid to the value properties that expose the bits and
then bind the control to the DataRowView exposed by the data set. This
should provide you with two-way data binding.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"TD" <so*****@somewh ere.comwrote in message
news:OH******** ******@TK2MSFTN GP05.phx.gbl...
Without posting a bunch of code from my class that implements
INotifyProperty Changed which is ButtonStateValu e, I still don't see how to
be able to bind this to the individual properties inside a DataSet ... or
am I going about this the wrong way?

ButtonStateValu e bValue = new ButtonStateValu e();

bValue.ButtonSt ate = ButtonStateEnum .Enabled | ButtonStateEnum .Visible;

DataTable dt = new DataTable();

dt.Columns.Add( "Flags", typeof(ButtonSt ateValue));

dt.Rows.Add(bVa lue);

buttonBound.Dat aBindings.Add(" Enabled", dt, "Flags" );

buttonBound.Dat aBindings.Add(" Visible", dt, "Flags");

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote
in message news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>TD,

No, you can't do this directly. I would create an adapter class,
which takes the bitmask and then has a number of boolean properties, one
for each bit in the mask. Then, you can set/get the values, and then
have a property which is the value of the assemblied bitmask.

You can have to implement the INotifyProperty Changed interface, and
fire the PropertyChanged event any time any of the values change.

You then should be able to bind to an instance of that adapter.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"TD" <so*****@somewh ere.comwrote in message
news:Of******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Is there a way to DataBind controls to a specific Bit in Bitmask? Here
is some sample code of what I am trying to do ... I am trying to bind
the Visible and Enabled properties of a Button to specific bits in a
Bitmask stored in a DataTable.

namespace Test

{

[Flags]

public enum ButtonStateEnum

{

Enabled = 0x001,

Visible = 0x002,

}

public partial class Form1 : Form

{

public Form1()

{

InitializeCom ponent();

}

private void Form1_Load(obje ct sender, EventArgs e)

{

// Boolean bValue = true;

ButtonStateEn um bValue = ButtonStateEnum .Enabled |
ButtonStateEn um.Visible;

DataTable dt = new DataTable();

dt.Columns.Ad d("Flags", typeof(ButtonSt ateEnum));

dt.Rows.Add(b Value);

buttonBound.D ataBindings.Add ("Enabled", dt, "Flags" );

buttonBound.D ataBindings.Add ("Visible", dt, "Flags");

}

}

}




Aug 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8750
by: Tongu Yumruk | last post by:
Hi, I'm looking for a way to represent bit-level data in python. Something like 0xDEADBEEF representation, but not for hex i'm looking for binary. Something like the %00110101 representation I used in pascal... Of course I can make my operations with ordinary integers but binary representation makes the code easier to read. -- Love, Respect, Linux
1
3208
by: Andrey Brozhko | last post by:
Hi I need to represent custom type system (ints, bytes, chars, enums, bitmasks, arrays and some other types) in xml. It is easy to see how to represent enums in xml (using xs:enumeration), the same is true for numeric types. Even arrays have an obvious description in schema: <complexType name="IntArray"> <sequence> <element name="item" type="int" minOccurs="0" maxOccurs="unbounded"/>
3
20503
by: Mark Allison | last post by:
Hi, Total newbie here, I'm trying to examine a bitmask which is passed into my app as a string. I convert it to int, and try and process it. I got the following code: //dbStatus current is a string int idbStatus = Convert.ToInt32(dbStatus); string dbStatusText = string.Empty;
5
2248
by: Andy | last post by:
Sigh... working on it for whole day and got no idea... Basically I want to have a bitmask filtering function, I will throw in 3 parameters: bitMaskValue - current bitmask value filterValue - the value I want to see if its exist in "bitMaskValue" BiggestValue - the maximum individual value can be exist And I want it just to return true if the value exist, or false if not
1
5977
by: Just D | last post by:
All, What's the easiest way to convert the string like 1001010101101010101 into a binary mask of type Int64 and back? ConvertBitmask or something like that? Just D.
1
1235
by: JJ_ | last post by:
It's possible binding a dataset and use dataset's haschange property in webform? Thanks
0
2089
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function that can draw a rainbow, and each color of the rainbow can be turned on or off individually. My function specification can be of this form: “rainbow(red, orange, yellow, green, blue, violet, purple)”. Each parameter is a true or false value....
3
1991
by: Patrick | last post by:
Hi there, I have a simple problem to solve but somehow I am too stupid to figure out where is the error. Basically, I wanna shift each element of the array by an amount of n, whereas the n highest bits shifted out should be the n-least significant bits of the next higher word. I tried doing this by shifting the words the amount of n to the left which works fine. In the next step I shift the lower
10
8487
by: lithiumcat | last post by:
Hi, This question seems to come up quite often, however I haven't managed to find an answer relevant to my case. I often use binary flags, and I have alaways used a "bitmask" technique, that is using #defined or const int powers of two, and using the following primitives : /* declaration and initizalisation of flags */ int flags = 0; /* setting flag */ flags |= FLAG_1;
0
8401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8824
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2818
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.