listview display problem

  • Thread starter Thread starter john sun
  • Start date Start date
J

john sun

Hi,
I met a strange problem during playing listView control.

If I create the control following the InitializeComponent(), then it
displayed well at the beginning. If later on I want dynamically
change-remove all existing column headers and all items, add new header and
items, the listview control just displayed empty.

I am using C# under vs .net 7.0 for this winform app.

Thanks for help!

John
 
* "john sun said:
I met a strange problem during playing listView control.

If I create the control following the InitializeComponent(), then it
displayed well at the beginning. If later on I want dynamically
change-remove all existing column headers and all items, add new header and
items, the listview control just displayed empty.

I am using C# under vs .net 7.0 for this winform app.

Post code.
 
Hi

code is as below:

basically, FillIistView() will be called at initial time of win form. After
that, when user click button, ListView's column and items will be
reconstructed.



Thanks for help

Best regards,

John

private void buttonQuery_Click(object sender, System.EventArgs e)

{

FillListView();

}

private void FillListView()

{

this.listViewRs.Clear();



ListViewItem item1 = new ListViewItem("item1",0);

item1.Checked = true;

item1.SubItems.Add("1");

item1.SubItems.Add("2");

item1.SubItems.Add("3");

ListViewItem item2 = new ListViewItem("item2",1);

item2.SubItems.Add("4");

item2.SubItems.Add("5");

item2.SubItems.Add("6");

ListViewItem item3 = new ListViewItem("item3",0);

// Place a check mark next to the item.

item3.Checked = true;

item3.SubItems.Add("7");

item3.SubItems.Add("8");

item3.SubItems.Add("9");

// Create columns for the items and subitems.

this.listViewRs.Columns.Add("Item Column", -2, HorizontalAlignment.Left);

this.listViewRs.Columns.Add("Column 2", -2, HorizontalAlignment.Left);

this.listViewRs.Columns.Add("Column 3", -2, HorizontalAlignment.Left);

this.listViewRs.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

//Add the items to the ListView.

this.listViewRs.Items.AddRange(new ListViewItem[]{item1,item2,item3});

}
 
John

It's the -2 for ColumnWidth, that and -1 FAILS. Actually, the columns are there if you put you
cursor close to the left edge of the headers you'll see it change to a set of parallel lines, click an
draq and you'll open them up :*

Have Fun

LES
 
Back
Top