My environment is Visual Studio 2012 Express.
I have a usercontrol that contains a ListView.
I need to let the user set at least the ListView appearance, so I exposed the Columns property :
[ in usercontrol ]
public ListView.ColumnHeaderCollection Columns {
get { return listView.Columns; }
}
When I put the control on a form, the Columns property shows up in the Properties panel and
I am able to add columns and so on.
Yet, at runtime the columns are not displayed ( although the View property is set to Details ).
Am I missing something ?
Update
I think this may be of some interest so I'll elaborate my comment at Hans Passant below :
I created a dummy UserControl with an embedded ListView, exposing its Columns and View properties as public.
This allows to edit them from the Properties panel.
When editing the embedded ListView in the IDE using the ColumnHeaders collection editor,
the resulting code in the Form Designer class looks like this :
...
//
// userControl1
//
this.userControl1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.userControl1.Location = new System.Drawing.Point(12, 12);
this.userControl1.Name = "userControl1";
this.userControl1.Size = new System.Drawing.Size(260, 161);
this.userControl1.TabIndex = 0;
...
Since I set the View to Details, there should be one more line :
this.userControl1.View = System.Windows.Forms.View.Details;
Without this line, the ListView won't display the column headers at runtime.
Somehow, the IDE fails to put the line in the Form Designer; if the line is added by hand, it works as expected.
The puzzling thing is that I added a debug message in the Form_Load event sink
private void Form1_Load(object sender, EventArgs e) {
MessageBox.Show("Columns : " + userControl1.Columns.Count + "\r\nView : " +
userControl1.View.ToString());
}
and it displays View : Details in both cases.