Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > datagrid column period-delimited hierarchy binding
 

datagrid column period-delimited hierarchy binding

Hi!

In custom field there is a possibility to databind period-delimited hierarchical object.

Like:
Binding b = new Binding("Text", ds, "customer.Order.OrderAmount");

But what I'm truely miss is to bind a period-delimeted hierarchical object to the datagrid column.
this.ColumnProductName.DataPropertyName = "Product.Name";
this.ColumnProductName.HeaderText = "Product in database";
this.ColumnProductName.Name = "ColumnProductName";

The result column values will be empty, altough when I debug this IList<Orders> list then there is all data present.

So it seems that grid columns does not support this kind of hierarchical databinding likeother controlsthat using Binding object and period-delimited hierarchical databindingscenarios like "Product.Name" :(

Is there a work around of this ???

ps: ColumnProductName is aDataGridViewTextBoxColumn

Lauri  Monday, December 18, 2006 9:31 AM
So if there is no eazy way I made custom refleciton class
PropertyUtils

public static object GetPropertyValue(Object o, String name)

{

if (o == null) return null;

Type t = o.GetType();

string[] members = name.Split(new char[] { '.' });

//Iterate every . separated element to return the value

foreach (String member in members)

{

foreach (PropertyInfo inf in t.GetProperties())

{

if (inf.Name == member)

{

o = inf.GetValue(o, null);

if (o == null)

return null;

break;

}

}

t = o.GetType();

}

return o;

}

and a custom column and everything works as a charm!!!

Lauri  Monday, December 18, 2006 12:41 PM
So if there is no eazy way I made custom refleciton class
PropertyUtils

public static object GetPropertyValue(Object o, String name)

{

if (o == null) return null;

Type t = o.GetType();

string[] members = name.Split(new char[] { '.' });

//Iterate every . separated element to return the value

foreach (String member in members)

{

foreach (PropertyInfo inf in t.GetProperties())

{

if (inf.Name == member)

{

o = inf.GetValue(o, null);

if (o == null)

return null;

break;

}

}

t = o.GetType();

}

return o;

}

and a custom column and everything works as a charm!!!

Lauri  Monday, December 18, 2006 12:41 PM

You can use google to search for other answers

Custom Search

More Threads

• DGV addingnew but no data
• Popualting Combo Box
• Copy all content from datagridview to clipboard
• Dynamically create DataGridView Event Handler
• DataGridView Seek
• how to expand and collapse rows in DataGrid to create parent/child relationships using a single table!?
• How to Force a Cell into Edit Mode in a DataGridView
• Binding Treeview to Data
• DataGridView Prevent user from leaving row on error
• XML Databinding in Windows Form