471,075 Members | 1,148 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

Binding ArrayList full of custom objects to DataGrid

All,

I am binding an ArrayList full of custom objects to an DataGrid. The
property in the custom class are all public.
I define a DataGridTableStyle and set the MappingName to "ArrayList". I
then add a DataGridTextBoxColumn for each of the properties in my custom
class which define a MappingName --> property name in class as well as
header text.
When I run the form, I see correct number of rows displayed, but none of the
columns appear. What am I missing?

Thank you in advance!

Berg

private void BindArrayListToGrid(IList results)

{

searchResults.DataSource = results;

DataGridTableStyle ts = new DataGridTableStyle();

ts.MappingName = "ArrayList";

int colwidth = (searchResults.ClientSize.Width

- ts.RowHeaderWidth

- SystemInformation.VerticalScrollBarWidth - 5) / 2;

// Create a column for the "districtKey" property

// defined in the districtKey Class

DataGridTextBoxColumn cs = new DataGridTextBoxColumn();

cs.MappingName = "districtKey"; // Public property name

cs.HeaderText = "District Key";

cs.Format = "f4";

cs.Width = colwidth;

ts.GridColumnStyles.Add(cs);

// Create a column for the "Telephone" property

// defined in the Telephone Class

cs = new DataGridTextBoxColumn();

cs.MappingName = "Telephone"; // Public property name

cs.HeaderText = "Telephone";

cs.Format = "f4";

cs.Width = colwidth;

ts.GridColumnStyles.Add(cs);

// Add the custom tablestyle to the DataGrid

searchResults.TableStyles.Clear();

searchResults.TableStyles.Add(ts);

}
Nov 16 '05 #1
0 1571

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by K | last post: by
5 posts views Thread by Dalibor Kusic | last post: by
3 posts views Thread by Rami | last post: by
5 posts views Thread by Alex Nitulescu | last post: by
5 posts views Thread by Rami | last post: by
2 posts views Thread by Merk | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.