ListView control problem.

A

Andrew

Hello, friends,

I know this sounds stupid, but I could not figure it out. So, help please.

I have ListView control in Details view and I need to populate. I used the
following code

for (int count = 1; count <= 50; count++)
{
ListViewItem listViewItem = new ListViewItem();
listViewItem.Text = "Page " + count.ToString();
listViewItem.Tag = count.ToString();
this.ListViewPageNumber.Items.Add(listViewItem);
}

However, to my surprise, I saw NOTHING in the list box, except the vertical
scroll bar was displayed.

Any ideas?
 
R

RappyFood

You need to define column headers for the listview control to display in
details mode. You can do this at design time by adding to the listview
control's columns collection, or you can modify your code to look like this:


ColumnHeader ch = new ColumnHeader();
ch.Text = "Page Number";
this.ListViewPageNumber.Columns.Add(ch);

for (int count = 1; count <= 50; count++)
{
ListViewItem listViewItem = new ListViewItem();
listViewItem.Text = "Page " + count.ToString();
listViewItem.Tag = count.ToString();
this.ListViewPageNumber.Items.Add(listViewItem);
}

RappyFood
 
A

Andrew

Thank, Rappy Food, it worked.

But, when I tried to select all the items using with HideSelection = false:

private void ButtonSelectAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.ListViewPageNumber.Items.Count; i++)
{
this.ListViewPageNumber.Items.Selected = true;
}
}

I could NOt see the items being selected. This control is really weired.

Any ideas? Thanks.
 
R

RappyFood

Interesting

It seems that you can only see the selected items when the control itself is
selected.
I added one line to your code, shifting focus to the listview control.
I think that it is possible to see the selected items when the control does
not have the focus, but I haven't figured it out yet.

[vc#]
private void ButtonSelectAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.ListViewPageNumber.Items.Count; i++)
{
this.ListViewPageNumber.Items.Selected = true;
}
this.ListViewPageNumber.Select();
}
[/vc#]


Sorry about the delay. I tend to get distracted.

RappyFood


Andrew said:
Thank, Rappy Food, it worked.

But, when I tried to select all the items using with HideSelection =
false:

private void ButtonSelectAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.ListViewPageNumber.Items.Count; i++)
{
this.ListViewPageNumber.Items.Selected = true;
}
}

I could NOt see the items being selected. This control is really weired.

Any ideas? Thanks.


RappyFood said:
You need to define column headers for the listview control to display in
details mode. You can do this at design time by adding to the listview
control's columns collection, or you can modify your code to look like
this:


ColumnHeader ch = new ColumnHeader();
ch.Text = "Page Number";
this.ListViewPageNumber.Columns.Add(ch);

for (int count = 1; count <= 50; count++)
{
ListViewItem listViewItem = new ListViewItem();
listViewItem.Text = "Page " + count.ToString();
listViewItem.Tag = count.ToString();
this.ListViewPageNumber.Items.Add(listViewItem);
}

RappyFood
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top