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);
}