See the following sample, that shows how to organize data to display and edit in TwoNumbersColumn:
[c#]
private void Form1_Load(object sender, System.EventArgs e)
{
InitFlyGrid(flyGrid);
}
//data class to display
public class Data : IFormattable
{
public readonly double First;
public readonly double Second;
public Data(double first, double second)
{
this.First = first;
this.Second = second;
}
#region IFormattable Members
public string ToString(string format, IFormatProvider formatProvider)
{
return First.ToString(format, formatProvider)+\"\\r\\n\" +
Second.ToString(format, formatProvider);
}
#endregion
}
//column that will display and edit two numbers
public class TwoNumbersColumn : NumberColumnBase, ISupportsTranslateValue
{
public TwoNumbersColumn(string name) : base(name){}
public override StringFormatFlags FormatFlags
{
get
{
StringFormatFlags baseFF = base.FormatFlags;
//turn on wordwrap
baseFF &= ~StringFormatFlags.NoWrap;
return baseFF;
}
}
#region ISupportsTranslateValue Members
public object TranslateToValue(object data)
{
string strData = data as string;
if (strData != null)//parse data
{
System.Globalization.NumberFormatInfo currentInfo = System.Globalization.NumberFormatInfo.CurrentInfo;
int sepindex = strData.IndexOf(\"\\r\\n\");
string first = sepindex != -1 ? strData.Substring(0, sepindex) : strData;
string second = sepindex != -1 ? strData.Substring(sepindex + 2) : string.Empty;
double dfirst = first != null && first != string.Empty ? double.Parse(first, currentInfo) : 0;
double dsecond = second != null && second != string.Empty ? double.Parse(second, currentInfo) : 0;
return new Data(dfirst, dsecond);
}
return null;
}
public object TranslateValue(object data)
{
return base.GetTextValue(data);
}
#endregion
}
private void InitFlyGrid(FlyGrid flyGrid)
{
flyGrid.BeginInit();
try
{
//increase rows height to display two rows of numbers
flyGrid.Rows.DefaultRowHeight = 46;
TwoNumbersColumn twoNumbersColumn = new TwoNumbersColumn(\"Data\");
//align data
twoNumbersColumn.TextAlign = ContentAlignment.MiddleRight;
//fit to width
twoNumbersColumn.FitMode = ColumnFitMode.Spring;
flyGrid.Columns.Options |= ColumnsOptions.FitToWidth;
//add column
flyGrid.Columns.Items.Add(twoNumbersColumn);
//add nodes with data (in this sample - randomly generated)
Random rnd = new Random();
for(int i=0; i < 10; i++)
{
//create data
Data data = new Data(rnd.NextDouble(), rnd.NextDouble());
//add node with data
flyGrid.Rows.Items.Add(new Node(data));
}
}
finally
{
flyGrid.EndInit();
}
}