Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Bitmask Databing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TD - 20 Aug 2007 18:22 GMT
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()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

// Boolean bValue = true;

ButtonStateEnum bValue = ButtonStateEnum.Enabled | ButtonStateEnum.Visible;

DataTable dt = new DataTable();

dt.Columns.Add("Flags", typeof(ButtonStateEnum));

dt.Rows.Add(bValue);

buttonBound.DataBindings.Add("Enabled", dt, "Flags" );

buttonBound.DataBindings.Add("Visible", dt, "Flags");

}

}

}
Nicholas Paldino [.NET/C# MVP] - 20 Aug 2007 19:57 GMT
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 INotifyPropertyChanged 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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> 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
[quoted text clipped - 53 lines]
>
> }
TD - 20 Aug 2007 22:56 GMT
Without posting a bunch of code from my class that implements
INotifyPropertyChanged which is ButtonStateValue, 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?

ButtonStateValue bValue = new ButtonStateValue();

bValue.ButtonState = ButtonStateEnum.Enabled | ButtonStateEnum.Visible;

DataTable dt = new DataTable();

dt.Columns.Add("Flags", typeof(ButtonStateValue));

dt.Rows.Add(bValue);

buttonBound.DataBindings.Add("Enabled", dt, "Flags" );

buttonBound.DataBindings.Add("Visible", dt, "Flags");

> TD,
>
[quoted text clipped - 65 lines]
>>
>> }
Nicholas Paldino [.NET/C# MVP] - 21 Aug 2007 21:19 GMT
You aren't going to be able to bind it to the data set.  The
INotifyPropertyChanged 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 IBindableComponent
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Without posting a bunch of code from my class that implements
> INotifyPropertyChanged which is ButtonStateValue, I still don't see how to
[quoted text clipped - 84 lines]
>>>
>>> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.