StrataFrame Forum

Column headers are not displaying...

http://forum.strataframe.net/Topic18911.aspx

By William John Tello - 9/2/2008

I have included some source code below which demonstrates what I'm attempting to do.  I have derived my own ListView control from the StrataFrame base ListView control.  I am attempting to dynamically build my column headers from the business object.  All of the data is populating in the business object without a hitch, but I'm having problems with getting the column headers to display properly.

(I learned most of what I'm doing from watching what StrataFrame creates in the form designer when I enter columns manually, etc.)

Any ideas where I might be going wrong?

public virtual void FillRows(MicroFour.StrataFrame.Business.BusinessLayer bo, string dataRetrievalMethodToExecute)

{

// set initial properties

base.SuspendLayout();

base.ListPopulating += new MicroFour.StrataFrame.UI.Windows.Forms.ListView.ListPopulatingEventHandler(OnListPopulating);

base.RowPopulating += new MicroFour.StrataFrame.UI.Windows.Forms.ListView.RowPopulatingEventHandler(OnRowPopulating);

base.AutoColumnSort = true;

base.AutoNavigateToSelectedRecord = true;

base.FullRowSelect = true;

base.GridLines = true;

base.View = View.Details;

// set up the business object

base.BusinessObject = bo;

// set up columns automatically

MicroFour.StrataFrame.UI.ListViewPopulationColumn OHRLVPopCol;

int i = 0;

string[] displayFields = bo.AllFieldsList.ToArray();

foreach (string field in displayFields)

{

base.Columns.Add(new ColumnHeader());

OHRLVPopCol = new MicroFour.StrataFrame.UI.ListViewPopulationColumn();

OHRLVPopCol.FormatString = "{" + i++ + "}";

OHRLVPopCol.PopulationType = MicroFour.StrataFrame.UI.ListViewColumnPopulationType.FormattedString;

OHRLVPopSettings.FormatColumns.Add(OHRLVPopCol);

}

OHRLVPopSettings.DisplayFieldNames.AddRange(displayFields);

OHRLVPopSettings.BusinessObjectType = bo.GetType().ToString();

OHRLVPopSettings.DropDownFormatString = "";

OHRLVPopSettings.FormatString = "{0}";

OHRLVPopSettings.MethodToExecute = dataRetrievalMethodToExecute + ";";

OHRLVPopSettings.ValueMember = bo.PrimaryKeyField;

base.PopulationDataSourceSettings = OHRLVPopSettings;

// fill the list view with x number of records

base.Requery();

base.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

base.ResumeLayout();

// select the first element in the list view

if (Items.Count > 0)

Items[0].Selected = true;

}

By William John Tello - 9/2/2008

I figured this out.  Instead of doing
base.Columns.Add(new ColumnHeader());
within my loop, I am now doing
base.Columns.Insert(i, displayFields[i]);
and my column headers are appearing exactly as I want them to.