ListView Colums

O

Ohad Young

Hi,

I'm using a ListView control in my application to display a list of items.
For each item its name and status (e.g., ordered, unordered, etc.) are
presented.
I added two column headers during the design time : One for the item's name,
and the second for the item's status.
The ListView control View property is set to "Details" mode.
It works well, but it also displays a third column with no header name.
However, the columns collection count is 2 (as it should).
What is this mysterious third column?
How do I get rid of displaying the unnecessary column?
Can I control the number of items presented in the ListView control?

Thanks, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: (e-mail address removed)
 
T

Tim Wilson

What is this mysterious third column?
This is an expected "filler column". It just consumes the rest of the space
between the last column and the edge of the ListView.
How do I get rid of displaying the unnecessary column?
Set the last columns width to -2. One thing to note is that if the ListView
might change size at runtime (because, for example, it is anchored) then you
will need to set the column width of the last column to -2 again to get it
to resize appropriately. So one way to do this is by hooking into the Resize
event.
C# Example:
private void listView1_Resize(object sender, System.EventArgs e)
{
this.listView1.Columns[1].Width = -2;
}
Can I control the number of items presented in the ListView control?
I am not exactly sure what you mean by this. Could you explain this a bit
more.
 
O

Ohad Young

Hi Tim,

Thanks it did the trick (-2).

Regarding my 2nd question:
I am not exactly sure what you mean by this. Could you explain this a bit
more.

The ListView control displays unnecessary rows (rows without any items)
according to the space it occupies due
to the Dock property set to fill.
Which property to set in order for it to display exactly the number of rows
as the actual number of items it contains?
BTW, if the number of items is very large I can always set it to a certain
maximum number and set the Scrolable property to true.
Hope it's clearer now.

Thanks, Ohad

Tim Wilson said:
What is this mysterious third column?
This is an expected "filler column". It just consumes the rest of the space
between the last column and the edge of the ListView.
How do I get rid of displaying the unnecessary column?
Set the last columns width to -2. One thing to note is that if the ListView
might change size at runtime (because, for example, it is anchored) then you
will need to set the column width of the last column to -2 again to get it
to resize appropriately. So one way to do this is by hooking into the Resize
event.
C# Example:
private void listView1_Resize(object sender, System.EventArgs e)
{
this.listView1.Columns[1].Width = -2;
}
Can I control the number of items presented in the ListView control?
I am not exactly sure what you mean by this. Could you explain this a bit
more.

--
Tim Wilson
.Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}

Ohad Young said:
Hi,

I'm using a ListView control in my application to display a list of items.
For each item its name and status (e.g., ordered, unordered, etc.) are
presented.
I added two column headers during the design time : One for the item's name,
and the second for the item's status.
The ListView control View property is set to "Details" mode.
It works well, but it also displays a third column with no header name.
However, the columns collection count is 2 (as it should).
What is this mysterious third column?
How do I get rid of displaying the unnecessary column?
Can I control the number of items presented in the ListView control?

Thanks, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: (e-mail address removed)
 
T

Tim Wilson

If the control has it's Dock property set to Fill then it is going to occupy
a certain size on the Form no matter what size you specify. But without the
control being "docked" you can autosize the ListView, in "Details" View,
using the method below:

// Call this to auto-size. The second parameter allows you to
// specify the number of items to display; -1 to display all.
AutoSizeListView(this.listView1, -1);

private void AutoSizeListView(ListView lvw, int displayItemCount)
{
if (lvw.Items.Count > 0)
{
Rectangle itemRect = lvw.GetItemRect(0);
int borderSpace = (lvw.Bounds.Height - lvw.ClientRectangle.Height);
lvw.Height = itemRect.Top + (itemRect.Height * ((displayItemCount > -1)
? displayItemCount : lvw.Items.Count)) + borderSpace;
}
}

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}

Ohad Young said:
Hi Tim,

Thanks it did the trick (-2).

Regarding my 2nd question:
I am not exactly sure what you mean by this. Could you explain this a
bit
more.

The ListView control displays unnecessary rows (rows without any items)
according to the space it occupies due
to the Dock property set to fill.
Which property to set in order for it to display exactly the number of rows
as the actual number of items it contains?
BTW, if the number of items is very large I can always set it to a certain
maximum number and set the Scrolable property to true.
Hope it's clearer now.

Thanks, Ohad

Tim Wilson said:
What is this mysterious third column?
This is an expected "filler column". It just consumes the rest of the space
between the last column and the edge of the ListView.
How do I get rid of displaying the unnecessary column?
Set the last columns width to -2. One thing to note is that if the ListView
might change size at runtime (because, for example, it is anchored) then you
will need to set the column width of the last column to -2 again to get it
to resize appropriately. So one way to do this is by hooking into the Resize
event.
C# Example:
private void listView1_Resize(object sender, System.EventArgs e)
{
this.listView1.Columns[1].Width = -2;
}
Can I control the number of items presented in the ListView control?
I am not exactly sure what you mean by this. Could you explain this a bit
more.

--
Tim Wilson
.Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}

Ohad Young said:
Hi,

I'm using a ListView control in my application to display a list of items.
For each item its name and status (e.g., ordered, unordered, etc.) are
presented.
I added two column headers during the design time : One for the item's name,
and the second for the item's status.
The ListView control View property is set to "Details" mode.
It works well, but it also displays a third column with no header name.
However, the columns collection count is 2 (as it should).
What is this mysterious third column?
How do I get rid of displaying the unnecessary column?
Can I control the number of items presented in the ListView control?

Thanks, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: (e-mail address removed)
 

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

Similar Threads


Top