|
-
Jun 7th, 2007, 11:11 AM
#1
Thread Starter
Hyperactive Member
[2.0] DataGridView Objects Probs.
Hi
Suppose I have a Class Person, with a property "Surname".
I have a dataTable such as:
Code:
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Surname",typeof(Person));
dt.Columns.add(dc);
Create an Instance of Person:
Code:
Person prs = new Person();
prs.Surname = "Rauland";
I now, create a dataRow:
Code:
DataRow dr = dt.CreateRow();
dr["Surname"] = prs;
dt.rows.add(dr);
I now use this dataTable as a dataSource to a dataGridView, named dbTest;
This grid has a column named, "Surname".
And have set the DataPropertyName to "Surname".(Meaning that it will display in this column the DataTable´s column with name "Surname")
Code:
dbTest.DataSource = dt;
The only thing it displays the type of object, in this case, Person.
Is there a way to set what in other controls is called "DisplayMember", the DataTables´s column named "Surname", to display the Person´s property "Surname".
Thanks!!
Last edited by Rauland; Jun 7th, 2007 at 04:23 PM.
Reason: Code correction,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|