This is part two of a three part series on working with master-detail data. In part one I showed how to present detail values on the master using a utility I wrote called the SubAttributeAccessor. In this article I will go into detail as to how the SubAttributeAccessor works. In part three, I’ll introduce a descendant of DataGridViewColumn that will allow us to show the indexed detail data in line with the master data as additional columns.
The SubAttributeAccessor is a class that when added to a parent class is able to present a list of children as an indexed property of the parent. For example, let’s imagine that we had a class called song and that is has among other properties one that is a list of attribute objects.
public class Song {
public List<Attribute> Attributes {get; set;}
}
The attribute class on the other hand has at least two properties, a key and a value. The key property is a string that will be used to identify the attribute and the value property would hold the actual value of the attribute. Rather than a certain type or even an object, the value will hold a byte buffer where we can store anything using serialization.
public class Attribute {
public string Key {get; set;}
public byte[] Value {get; set;}
}
These two classes form the basis of the imaginary scenario that I used in part one of this article. A song can have an unlimited number of attributes. As things stand, we can add an attribute to a song like so:
Song mySong = new Song();
Attribute myAttribute = new Attribute();
myAttribute.Key = "Tempo";
myAttribute.Value = "slow";
mySong.Attributes.Add(myAttribute);
More...
3826c767-a96f-4e92-886b-c5c2ebe94a05|0|.0