<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx</link><description>This is a frequently asked question. Suppose that we have a class Person which has a property of type Address(another class). The class Address has its own properties. Now we create a collection of Person objects, e.g. List&amp;lt;Person&amp;gt; and would like</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#1571549</link><pubDate>Thu, 01 Feb 2007 13:00:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1571549</guid><dc:creator>Marc C</dc:creator><description>&lt;p&gt;Thanks Linda this was what I was looking for.&lt;/p&gt;
&lt;p&gt;I would like to be able to have an class that implements runtime properties. Then attach to a objectDataSource control and hook the objectDataSource to a gridview.&lt;/p&gt;
&lt;p&gt;After making a few changes to the code I was able to get it almost working but there are a few problems.&lt;/p&gt;
&lt;p&gt;1) The dynamic fields do not appear by default in the gridview. They are in the bindable field list but they are not in the selected list.&lt;/p&gt;
&lt;p&gt;2) When I hit the refresh schema button in the designer an error occurs saying that one of the dynamic properties already exists.&lt;/p&gt;
&lt;p&gt;Any help would be welcome.&lt;/p&gt;
&lt;p&gt;Marc&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#1612915</link><pubDate>Tue, 06 Feb 2007 20:43:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1612915</guid><dc:creator>Michael Bursill</dc:creator><description>&lt;p&gt;I ran into problems running this example, but was able to get it going with a few small changes. I'll post them here in case anyone else runs into this.&lt;/p&gt;
&lt;p&gt;1) In the GetProperties method change senderprop to addressPD. I'm not even sure what senderprop is?&lt;/p&gt;
&lt;p&gt;2) The wrong overloaded version of GetProperties is overridden. Use this one:&lt;/p&gt;
&lt;p&gt; public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)&lt;/p&gt;
&lt;p&gt;3) Because of #2 you should call GetProperties of the base like so:&lt;/p&gt;
&lt;p&gt;PropertyDescriptorCollection cols = base.GetProperties(attributes);&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#1613592</link><pubDate>Tue, 06 Feb 2007 22:55:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1613592</guid><dc:creator>Michael Bursill</dc:creator><description>&lt;p&gt;Here's a question...&lt;/p&gt;
&lt;p&gt;How do I make the now data bound second-level properties editable via the DataGridView?&lt;/p&gt;
&lt;p&gt;If I follow the sample here, when I try to use the DataGridView to change CityName I throw an Invalid Cast because the DataGridView is trying to set the string value CityName to the property HomeAddr.&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#1613867</link><pubDate>Tue, 06 Feb 2007 23:36:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1613867</guid><dc:creator>Michael Bursill</dc:creator><description>&lt;p&gt;Last time I post here, I swear ;-)&lt;/p&gt;
&lt;p&gt;I was able to make the DataGridView support editing of the first and second level properties. It only required two changes in the SubPropertyDescriptor.&lt;/p&gt;
&lt;p&gt;1) when returning the property type I return the sub property type, not the parent:&lt;/p&gt;
&lt;p&gt;public override Type PropertyType { get { return _subPD.PropertyType; } }&lt;/p&gt;
&lt;p&gt;2) When calling SetValue you need to find the value to set from inside the parent like this:&lt;/p&gt;
&lt;p&gt;_subPD.SetValue(_parentPD.GetValue(component), value);&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#1614559</link><pubDate>Wed, 07 Feb 2007 02:04:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1614559</guid><dc:creator>Marc C</dc:creator><description>&lt;p&gt;Michael thanks for the post.&lt;/p&gt;
&lt;p&gt;I will try your changes.&lt;/p&gt;
&lt;p&gt;Appreciate the work you put in.&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#2169522</link><pubDate>Wed, 18 Apr 2007 07:42:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2169522</guid><dc:creator>Linda</dc:creator><description>&lt;p&gt;Thanks Michael! I am terribly sorry that I made several mistakes in this artical. &lt;/p&gt;
&lt;p&gt;It should be 'PropertyDescriptorCollection homeAddr_child = addressPD.GetChildProperties();' in the override GetProperties method within the MyCustomTypeDescriptor class. &lt;/p&gt;
&lt;p&gt;In addition, what you've done to make the data bound second-level properties editable in the DataGridView is correct. &lt;/p&gt;
&lt;p&gt;But to get the DataGridView to bind to a second-level property in a data source, we only need to override the GetProperties method without parameter in the custom type descriptor.&lt;/p&gt;
&lt;p&gt;I will modify my sample code in the article.&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#2169547</link><pubDate>Wed, 18 Apr 2007 07:47:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2169547</guid><dc:creator>Linda</dc:creator><description>&lt;p&gt;Hi Marc, thank you for your interest in this article!&lt;/p&gt;
&lt;p&gt;It seems that your problem is related to ASP.NET. Right? Sorry that I am not familiar with ASP.NET. &lt;/p&gt;
&lt;p&gt;If you still need help, please explain your problem more in detail. &lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#2509192</link><pubDate>Wed, 09 May 2007 23:01:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2509192</guid><dc:creator>Erick</dc:creator><description>&lt;p&gt;Hi. I've tried but this is not working... I think I'm missing something...&lt;/p&gt;
&lt;p&gt;Maybe problems with names spaces of classes?&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#2642347</link><pubDate>Tue, 15 May 2007 08:56:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2642347</guid><dc:creator>Tom W</dc:creator><description>&lt;p&gt;One point of detail - is there a way to associate the newly created TypeDescriptionProvider with the target class without modifying the class file? &amp;nbsp;that is, do all the stuff mentioned here without having access to the source for the 'Person' class?&lt;/p&gt;
</description></item><item><title>Maybe you know the answer to this problem.</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#2821382</link><pubDate>Wed, 23 May 2007 22:12:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2821382</guid><dc:creator>Dave Beseke</dc:creator><description>&lt;p&gt;I am attempting to use a combo box in a datagrid view to select a value for a field from another table. &amp;nbsp;The table bound to the datagridview is a list of doctor's credentials. &amp;nbsp;The table bound to the combo box is a contact table. &amp;nbsp;I want to assign the contact table key value to a field in the doctor table. &amp;nbsp;I want to use the contact name as the display value. &amp;nbsp;When I attempt to do this, even though I have the name set as the displaymember and the key as the valuemember, the key value is being displayed instead of the name. &amp;nbsp;The correct display values are shown in the combobox when I click it, but as soon as I tab out of that field the key is displayed instead of the name. &amp;nbsp;Here's the code:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;doctorGrid.DataSource = doctorTable;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;doctorTable.Columns[&amp;quot;contactID&amp;quot;].DefaultValue = -1;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DataGridViewComboBoxColumn cbc = new DataGridViewComboBoxColumn();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.DataSource = nameTable;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.DataPropertyName = &amp;quot;contactID&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.DisplayMember = &amp;quot;contactName&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.ValueMember = &amp;quot;contactID&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.HeaderText = &amp;quot;Name&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.Width = 150;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.Name = &amp;quot;docName&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cbc.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;doctorGrid.Columns.Insert(2, cbc);&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#3170414</link><pubDate>Sat, 09 Jun 2007 01:44:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3170414</guid><dc:creator>Erick</dc:creator><description>&lt;p&gt;Hi, this article is great.&lt;/p&gt;
&lt;p&gt;But, what can I do for n-level properties?&lt;/p&gt;
&lt;p&gt;-Product&lt;/p&gt;
&lt;p&gt; -Category&lt;/p&gt;
&lt;p&gt; &amp;nbsp;-Subcategory&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#3695096</link><pubDate>Thu, 05 Jul 2007 02:13:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3695096</guid><dc:creator>caddzooks</dc:creator><description>&lt;p&gt;Thanks for a great example.&lt;/p&gt;
&lt;p&gt;One comment, is that you mentioned that a downsize to using ICustomTypeDescriptor was that it required modification of the class.&lt;/p&gt;
&lt;p&gt;However, your solution using TypeDescriptionProvider also requires that by way of the TypeDescriptionProvider attribute.&lt;/p&gt;
&lt;p&gt;You can apply your solution to any class, without having to apply the TypeDescriptionProvider attribute, by simply calling TypeDescriptor.AddProvider() to add the TypeDescriptionProvider for the type (or an instance of it). That means you can implement the solution for any class without the need for its source.&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#3962471</link><pubDate>Thu, 19 Jul 2007 23:41:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3962471</guid><dc:creator>Barry</dc:creator><description>&lt;p&gt;I have a question that might be the same as was asked by Erick.&lt;/p&gt;
&lt;p&gt;I have a multi-level class structure. Something like this:&lt;/p&gt;
&lt;p&gt;ClassA contains an instance of ClassB. ClassA employs a description provider to expose properties of ClassB. &lt;/p&gt;
&lt;p&gt;ClassB contains an instance of ClassC. Now I have implemented ITypedList on ClassA and ClassB to get at ClassC's properties, but cannot seem to get at them. Do I need to add GetChildProperties calls in ClassA to get the properties in ClassC? Nothing seems to work.&lt;/p&gt;
&lt;p&gt;Any help would be appreciated.&lt;/p&gt;
</description></item><item><title>RoleProvder - RoleTypeDescriptionProvider</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#4987841</link><pubDate>Wed, 19 Sep 2007 02:10:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4987841</guid><dc:creator>Mabsterama</dc:creator><description>&lt;p&gt;Here's the last step in creating our RoleProvider class, which surfaces custom properties for roles you&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#6807746</link><pubDate>Wed, 19 Dec 2007 19:32:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6807746</guid><dc:creator>Cassio Tavares</dc:creator><description>&lt;p&gt;Hi Linda. I adaptaded your solution to a more generic one using generics. This is what I was looking for. Thank you!!!&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#7357682</link><pubDate>Thu, 31 Jan 2008 23:21:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7357682</guid><dc:creator>CoderDude</dc:creator><description>&lt;p&gt;The dotnet framework is an excellent tool, with many shining features. However, in my mind this represents a truly fundamental design flaw. The level of complexity that needs to be invoked here to accomplish this simple task is unacceptable.&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#8369943</link><pubDate>Tue, 08 Apr 2008 23:54:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8369943</guid><dc:creator>Harold Valdivia Garcia</dc:creator><description>&lt;p&gt;Hi. Men and Women. I have an easy solution for this problem.&lt;/p&gt;
&lt;p&gt;If Oneself overrides ToString() of the object Addres,his DataGridview could show the second level.&lt;/p&gt;
&lt;p&gt;public override ToString()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;return cityname+&amp;quot; &amp;quot;postcode;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#8712934</link><pubDate>Wed, 09 Jul 2008 20:19:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8712934</guid><dc:creator>Guillermo</dc:creator><description>&lt;p&gt;How about overriding the CellFormatting event of the DataGridView and using reflection with something like the following?:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ((dataGridView1.Rows[e.RowIndex].DataBoundItem != null) &amp;amp;&amp;amp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(dataGridView1.Columns[e.ColumnIndex].DataPropertyName.Contains(&amp;quot;.&amp;quot;)))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string[] nameAndProp = dataGridView1.Columns[e.ColumnIndex].DataPropertyName.Split(new char[]{'.'});&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;object unboundValue = ((DataRowView)dataGridView1.Rows[e.RowIndex].DataBoundItem)[nameAndProp[0]];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyInfo objectProperty = unboundValue.GetType().GetProperty(nameAndProp[1]);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.Value = objectProperty.GetValue(unboundValue, null).ToString();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;This can be extended to make it recursive in case of nested subclasses...&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#8712992</link><pubDate>Wed, 09 Jul 2008 20:33:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8712992</guid><dc:creator>Guillermo</dc:creator><description>&lt;p&gt;Sorry, I forgot to add that in the column we can use the &amp;quot;dot notation&amp;quot; we're used to:&lt;/p&gt;
&lt;p&gt;this.dataGridView1.Columns[&amp;quot;name&amp;quot;].DataPropertyName = &amp;quot;Class.Property&amp;quot;;&lt;/p&gt;
</description></item><item><title>re: How to bind a DataGridView column to a second-level property of a data source</title><link>http://blogs.msdn.com/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx#9436478</link><pubDate>Fri, 20 Feb 2009 22:44:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9436478</guid><dc:creator>Suja Sebastian</dc:creator><description>&lt;p&gt;I know I am very late. But still, if you see my post, I am lucky.&lt;/p&gt;
&lt;p&gt;I am doing a &amp;quot;web&amp;quot; application and using listview and objectcontainerdatasource for binding. My classes are as follows.&lt;/p&gt;
&lt;p&gt; public class StudentContactCC : PersonCC&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		public StudentContactCC()&lt;/p&gt;
&lt;p&gt;		{ &lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		//Base Members&lt;/p&gt;
&lt;p&gt;		public String ContactID { get; set; }&lt;/p&gt;
&lt;p&gt;		public String StudentID { get; set; }&lt;/p&gt;
&lt;p&gt;		public String ContactType { get; set; }&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;public class Person&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	..&lt;/p&gt;
&lt;p&gt;	PhoneNumberCC HomePhone{get;set;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public class PhoneNumberCC&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		public String PersonID { get; set; }&lt;/p&gt;
&lt;p&gt;		public String PhoneID { get; set; }&lt;/p&gt;
&lt;p&gt;		public String PhoneType { get; set; }&lt;/p&gt;
&lt;p&gt;		public String AreaCode { get; set; }&lt;/p&gt;
&lt;p&gt;		public String ExchangeCode { get; set; }&lt;/p&gt;
&lt;p&gt;		public String LocalNumber { get; set; }&lt;/p&gt;
&lt;p&gt;		public String Extension { get; set; }&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;After reading your article I created the 3 classes:&lt;/p&gt;
&lt;p&gt; public class SubPropertyDescriptor : PropertyDescriptor&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private PropertyDescriptor _subPD;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private PropertyDescriptor _parentPD;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public SubPropertyDescriptor(PropertyDescriptor parentPD, PropertyDescriptor subPD, string pdname)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: base(pdname, null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_subPD = subPD;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_parentPD = parentPD;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override bool IsReadOnly { get { return false; } }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override void ResetValue(object component) { }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override bool CanResetValue(object component) { return true; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override bool ShouldSerializeValue(object component)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return true;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override Type ComponentType&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;get { return _parentPD.ComponentType; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override Type PropertyType { get { return _subPD.PropertyType; } }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override object GetValue(object component)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return _subPD.GetValue(_parentPD.GetValue(component));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override void SetValue(object component, object value)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_subPD.SetValue(_parentPD.GetValue(component), value);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OnValueChanged(component, EventArgs.Empty);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; public class StudentContactTypeDescriptionProvider : TypeDescriptionProvider&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private ICustomTypeDescriptor td;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public StudentContactTypeDescriptionProvider()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: this(TypeDescriptor.GetProvider(typeof(StudentContactCC )))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public StudentContactTypeDescriptionProvider(TypeDescriptionProvider parent)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: base(parent)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (td == null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;td = base.GetTypeDescriptor(objectType, instance);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;td = new StudentContactCCTypeDescriptor(td);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return td;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; public class StudentContactCCTypeDescriptor : CustomTypeDescriptor&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public StudentContactCCTypeDescriptor(ICustomTypeDescriptor parent)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: base(parent)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override PropertyDescriptorCollection GetProperties()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyDescriptorCollection cols = base.GetProperties();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyDescriptor homephonePD = cols[&amp;quot;HomePhone&amp;quot;];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyDescriptorCollection homePhone_child = homephonePD.GetChildProperties();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyDescriptor[] array = new PropertyDescriptor[cols.Count + 3]; //3 for each home,cell,work&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cols.CopyTo(array, 0);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;array[cols.Count] = new SubPropertyDescriptor(homephonePD, homePhone_child[&amp;quot;AreaCode&amp;quot;], &amp;quot;HomePhoneAreaCode&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;array[cols.Count + 1] = new SubPropertyDescriptor(homephonePD, homePhone_child[&amp;quot;ExchangeCode&amp;quot;], &amp;quot;HomePhoneExchangeCode&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;array[cols.Count + 2] = new SubPropertyDescriptor(homephonePD, homePhone_child[&amp;quot;LocalNumber&amp;quot;], &amp;quot;HomePhoneLocalNumber&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyDescriptorCollection newcols = new PropertyDescriptorCollection(array);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return newcols;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;Now, I created a list like this :&lt;/p&gt;
&lt;p&gt;[Serializable()]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class ContactList&amp;lt;T&amp;gt; : List&amp;lt;T&amp;gt;, ITypedList&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[NonSerialized()]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private PropertyDescriptorCollection properties;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public ContactList()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: base()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(typeof(T), new Attribute[] { new BrowsableAttribute(true) });&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pdc.Sort();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#region ITypedList Members&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public PropertyDescriptorCollection &amp;nbsp;GetItemProperties(PropertyDescriptor[] listAccessors)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; 	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyDescriptorCollection pdc = null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (null == listAccessors)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pdc = properties;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; StudentContactTypeDescriptionProvider ContactProvider = new StudentContactTypeDescriptionProvider();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; StudentContactCC Contact = new StudentContactCC();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; StudentContactCCTypeDescriptor Desccriptor = new StudentContactCCTypeDescriptor(ContactProvider.GetTypeDescriptor(Contact));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pdc = Desccriptor.GetProperties();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return pdc;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public string &amp;nbsp;GetListName(PropertyDescriptor[] listAccessors)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return typeof(T).Name;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#endregion&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;In my code behind, I assign a ContactList to my datasource:&lt;/p&gt;
&lt;p&gt; ContactList &amp;lt;StudentContactCC&amp;gt; Guardians = _controller.GetStudentContactList (_controller.GetStudentID());&lt;/p&gt;
&lt;p&gt;And I bind it to my datasource:&lt;/p&gt;
&lt;p&gt; &amp;nbsp;ocdsGuardians.DataSource = Guardians ;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ocdsGuardians.DataBind();&lt;/p&gt;
&lt;p&gt;In the UI, I do binding like this:&lt;/p&gt;
&lt;p&gt;&amp;lt;asp:TextBox ID=&amp;quot;txtHomePhoneAreaCode&amp;quot; runat=&amp;quot;server&amp;quot; Width=&amp;quot;2em&amp;quot; MaxLength=&amp;quot;3&amp;quot;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Text='&amp;lt;%# Bind(&amp;quot;HomePhoneAreaCode&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;/p&gt;
&lt;p&gt;When I go to the edit mode of my listview, areacode get populated.But when I try to update, I am not getting the user entered value.&lt;/p&gt;
&lt;p&gt;Please keep in mind that I am doing web development.&lt;/p&gt;
</description></item></channel></rss>