Welcome > In Depth articles > Sparse array databinding
Sparse array binding
A while ago, someone asked me a great question about sparsely populated arrays. More particularly, this person asked me
how to bind a sparsely populated array to a WPF grid control and I suddenly
realized that not only did a WPF grid control not know how to bind to a sparsely
populated array but moreover there were no sparsely populated arrays with which
to bind. I therefore had the double
conundrum of having to create both a collection type which allowed sparse
population and a grid control that would bind to it. In this first of two articles I’ll
show you how to create a fully customizable sparsely populated array that is
templated to take items of a specific type, in a second or article, I’ll show
you how to create the grid control which understands how to bind to this
collection object. Finally, you'll see how to create custom WPF templates
that enable you to greatly enhance the look of the control.
In case you’re not aware, a “sparse” array is one which has the normal
dimensions of any run of the mill array, for example a 10 by 10 two dimensional
array, in which the items at any coordinate need not necessarily be filled with
some actual item. For example, in
our 10 by 10 array we may only have eight items in the first row and then five
items in the second row followed by a 10 items in the third row and so on. Sparse arrays are interesting because
when re dimensioning such an array there is no requirement to change the amount
of memory used, we simply need to have a mechanism for the array to declare that
it has a different size. Happily,
net change notification systems, whether they know it or not, are able to cope
with these types of arrays even though the .net type system does not provide
one.
In case you’re still not clear, the illustration below shows a sparsely
populated array. The green squares represent items that are filled with
something. The blank ones don't exist. They need not even be stored as nulls.
Article 1: The sparse array collection
Article 2: The basic WPF sparse grid control
Article 3: Customising and testing.
|