Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
170
How to show BindingList<string> as columns instead of rows
posted

Hi Team,

I'm using DataSource to bind a class to the UltraGrid.

I have an object inside which there're nested lists of strings, like below, I want to show the deepest level as columns instead of rows. Is there a way I can achieve this?

I want the GUI looks like "FlatInnerObject", but I want to use list of string in code(like class "InnerObject") rather than list out all string properties(like class "FlatInnerObject"), as the length of attribute list could be changing. i.e., if there're 10 columns in FlatInnerObject, I don't want to list 10 string properties there...

private IBindingList _rows = new BindingList<OutterObject>();
public Form1()
{
InitializeComponent();

ultraGrid1.DataSource = _rows;

var outterObject = new OutterObject { Summary = "Testing Summary" };
var innerObject = new InnerObject();
innerObject.AddAttribute("column1");
innerObject.AddAttribute("column2");

outterObject.AddInnerObject(innerObject);
outterObject.AddInnerObject(innerObject);

var flatInnerObject = new FlatInnerObject() { Column1 = "flat column 1", Column2 = "flat column 2", };
outterObject.AddFlatInnerObject(flatInnerObject);
outterObject.AddFlatInnerObject(flatInnerObject);

_rows.Add(outterObject);

SetUpGridColumns();

}

public class OutterObject

{
private readonly BindingList<InnerObject> _innerObjects = new BindingList<InnerObject>();
private readonly BindingList<FlatInnerObject> _flatInnerObjects = new BindingList<FlatInnerObject>();

public string Summary { get; set; }

public BindingList<InnerObject> InnerObjects
{
get { return _innerObjects; }
}

public void AddInnerObject(InnerObject o)
{
_innerObjects.Add(o);
}

public BindingList<FlatInnerObject> FlatInnerObjects
{
get { return _flatInnerObjects; }
}

public void AddFlatInnerObject(FlatInnerObject o)
{
_flatInnerObjects.Add(o);
}
}

public class InnerObject
{
private readonly BindingList<string> _attributes = new BindingList<string>();

public BindingList<string> Attributes
{
get { return _attributes; }
}

public void AddAttribute(string a)
{
_attributes.Add(a);
}
}

public class FlatInnerObject
{
public string Column1 { get; set; }
public string Column2 { get; set; }
}