I’ve been wracking my brain the last couple of months writing some nice C# Stuff. The biggest thing I wanted personally form the project was event-driven, no polling required data flow.

It seems easy enough, and using the datasets/views/list it’s not too hard to make everything “just happen”… but, then comes the head ache.

Custom Controls. I developed a really nice intensity / heat graph. I personally think the most important job of any good program is displaying all valuable data, quickly, and effectively without the use of a scroll bar.

But, how the hell do i get my data over to it my new control? Making the control poll a defined datatable wouldn’t work, because that’ breaks the rules i set myself. NO POLLING for data. let it come to you , otherwise in some way, you’re wasting cpu cycles. And this way, even if you are, it’s someone elses background code just working it’s own magic with events already defined.

So… here we are… we’ve got our own control.. now, you ask, how do we set up databinding?

easy. put a dataView on your control somewhere, and hide it.
then, put this at the top of your user control class..

[System.ComponentModel.ComplexBindingProperties(”DataSource”, “DataMember”)]
public partial class WidgetControl : UserControl
{

then simply add this stuff after the class declaration

public object DataSource
{
get { return dataGridView1.DataSource; }
set { dataGridView1.DataSource = value; }
}

public string DataMember
{
get { return dataGridView1.DataMember; }
set { dataGridView1.DataMember = value; }
}

}
and wa-la, you’ve got data, you’ve got events, you’ve got a life… not much like my own.

Ah, how easy it is…

here’s some quick msdn articles:

Walkthrough: Creating a User Control that Supports Complex Data Binding


Walkthrough: Creating a User Control that Supports Simple Data Binding

j.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google]