Skip to content

Home

BindingListView - The DataView equivalent for custom collections

BindingListView is a project hosted on GotDotNet that gives you search, sorting and filtering capabilities to a plain BindingList. For example if you have the following Person entity:

public class Person 
{ 
    string firstName = string.Empty; 
    int age = 0;

    public string FirstName 
    { 
        get { return firstName; } 
        set { firstName = value; } 
    }

    public int Age 
    { 
        get { return age; } 
        set { age = value; } 
    }

    public Person(string firstName, int age) 
    { 
        this.firstName = firstName; 
        this.age = age; } 
    }
}

And you want to have a collection of persons bind to a datagrid, you can simply write the following:

BindingList<Person> persons = new BindingList<Person>(); 
persons.Add(new Person("Bill", 45)); 
persons.Add(new Person("Gert", 33)); 
persons.Add(new Person("Johan", 12)); 
persons.Add(new Person("An", 27));

personsGrid.DataSource = persons;

What if you need to do some filtering, or simply sorting on the datagrid? Therefore you would need to create a custom collection class that implements a bunch of interfaces for having sorting, filtering and searching capabilities.

The BindingListView class has all these functionalities built-in. You simply have to pass a list, and bind the BindingListView to the datagrid. The same way you would do with a DataSet and DataView. This means:

BindingListView<Person> personsView = new BindingListView<Person>(persons); 
personsGrid.DataSource = personsView;

Sorting on a BindingListView is done through the Sort property, the same as on a DataView. For example:

personsView.Sort = "FirstName";

Filtering is done through the Filter property and uses anonymous delegates. So for example to filter all persons that are less than 30, you can write:

personsView.Filter = BindingListView<Person>.CreateItemFilter(
    new Predicate<Person>(delegate(Person person) 
        {
            return (person.Age < 30); 
        } 
    ));

You can also merge multiple sources to one view (functionality that the DataView doesn't support) through the AggregatedBindingListView.

Extending WebBrowserSiteBase?

One of the ways for extending the WebBrowser 2.0 control is to inherit from WebBrowserSiteBase. According to the documentation, you have to override the method CreateWebBrowserSiteBase and return your specific implementation of WebBrowserSiteBase.

Everything is there to plug-in your implementation of WebBrowserSiteBase, but the problem is that the constructor of WebBrowserSiteBase is marked as internal, and so there is no way to inherit from. I am pretty sure that it was possible with the beta release of .NET 2.0, but for some reason they marked it as internal in the RTM version. This means that implementing some interfaces that are described here are not possible.

I am planning to release a .NET 2005 version of my IStaySharp.WebBrowser project. More info coming soon.

Come to www.istaysharp.net

Finally I have updated my site, called IStaySharp to MediaWiki. MediaWiki is one of the best wiki based engines available and it's written in PHP and MySQL. Thankfully my hosting, webhost4life, has PHP & MySQL support.

The intention of IStaySharp is to document and archive my code snippets, articles, components, projects, etc. that I am working on, and to share my experiences that I encounter during my .NET development. Visitors to the site can use the discussion page to give feedback, remarks, suggestions, etc. to the associated page.

I didn't encounter much problems when installing MediaWiki on webhost4life, except the e-mailing didn't work directly. The problem was that MediaWiki uses the format: myname <myname@domain.com>(mailto:myname@domain.com>) in the to field of the mail function, and with the current settings and setup of webhost4life this resulted in an invalid address. Therefore I had to change the method toString() of the MailAddress class inside UserMailer.php to

function toString() 
{ 
    return $this->address; 
} 

instead of

function toString() 
{ 
    if( $this->name != '' ) 
    { 
        return wfQuotedPrintable( $this->name ) . " <" . $this->address . ">"; 
    } 
    else 
    { 
        return $this->address; 
    } 
} 

IStaySharp uses also the extension that I wrote for having syntax highlighting. Some other nice extensions are coming!

New release of MediaWiki

I am planning to install MediaWiki for my site www.istaysharp.net. This way I can easily add/update content, because currently the site is static, and that's thre reason why it's not updated frequently.

It was planned for this evening to update www.istaysharp.net, but a new version has been released of MediaWiki, version 1.6.1. I hope the upgrade will go smooth and that my code will still work :)

One other interesting point, is that apparently there is an experimental support for connecting to an Oracle database (read release notes). Are there any plans for supporting MS SQL Server 2000? If so, please let me know!!!

Exception Handling

When reviewing code, you see a lot of 'bad' use of exception handling. As Pieter Gheysens mentioned, you see a lot of code that looks like:

try 
{ 
    // code statements 
} 
catch(Exception exc) 
{ 
    throw exc; 
} 

No extra logic defined inside the catch-block, like logging, and when it is meant to re-throw an exception, the throw statement must be used, instead of throw ex. The statement throw ex will erase the original stacktrace. Best practice for exception handling is

try 
{ 
    // code that could throw an exception 
} 
catch(Exception exc) 
{ 
    // log exception throw; 
}

In case of a traditional layered architecture, UI, Business Logic (BL) & Data Access Logic (DAL), you will catch a DAL exception inside the BL layer, and translate it to a 'meaningfull' business exception. Each layer has a specific purpose and domain, and so are the exceptions!

It's also a good idea to subscribe to the Application.ThreadException (in case of a form application) and do the logging in there. Here log4net is used as logging tool.

ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application\_ThreadException);

static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) 
{ 
    log.Error("Application error", e.Exception); 
    // show custom error dialog or throw 
}

New LCD Monitor

Recently I have a new LCD monitor, the Samsung 204B. It's a 20.1 inch LCD monitor, with a resolution of 1600 x 1200 and a response time of 5 ms.

I am freak when it comes to monitors. I like to have a high resolution and the quality of the screen must be perfect. My current monitor is a Sony F520 (CRT), which is very expensive, but it has a resolution of 2048 x 1536@86Hz and a pitch of 0.22mm. Therefore I was afraid about the quality of the Samsung 204B compared with my CRT monitor.

In one word, the quality is superb of the Samsung. The colors are vivid and the text is very clear (no ghosting or blur). No dead pixels found, has an ergonomic 4-way adjustable stand and I like the design very much. One more detail, it's about 50 pounds (23 kg) lighter than my current CRT monitor :)

Syncmaster_204B

Use the Graphics Processing Unit (GPU) inside your application

Modern GPUs are increasing in programmability and these chips can do more than just graphical computations. They can now be used as a coprocessor, and they can be integrated for a set of tasks. GPGPU (General-Purpose compuation on GPUs) is such an initiative that contains a catalog where the GPU can be used for general-purpose computation.

The big challenge, is to translate the everyday applications to two-dimensional graphic functions, like texture mapping. In other words: Pretend that everything is a game (source).

As an example in this article and results, a quicksort algorithm of 18 million records in Visual C++ took 21 seconds, while the GPU took 2 seconds! What are the results for a Quad SLI setup?

Microsoft research is apparently working on a system that simplifies the programming of GPU to general-purpose tasks, it's called Accelerator (simplified programming of graphics processing units for general-purpose uses via data-parallelism).

Wikipedia reaches 1 million articles

Wikipedia is the biggest and most famous online encyclopedia available. They have now more than 1 million articles, and it's still growing! This page gives you an idea about the architecture and the specification of the servers. The master database, called Samuel, contains all articles and has about a capacity of 400GB. Here you can monitor the wiki servers.