Home All Groups Group Topic Archive Search About
Author
17 Jan 2006 5:19 PM
WAkthar

Hi,

I need to be able to display a listview with the following functionality.
The listview must be able to display different types of information.
There are normally 3 types.
Type 1 has only 1 column.
The first row must display an icon showing the status of this type.
The following rows must display text messages.

Type 2 has only 2 columns
The first row, first column must display an icon showing the status of this
type.
The following rows, second column must display text messages.

Type 3 is similar.

Now for Type 1, I can get to display the icon but when I try to display
messages in the next rows they appear in the second column!

Here is the following code.



else if (type1Object != null)
{
if (!populated)
  AddType1ColumnsHeaders();

int mods = type1Object.Display;
switch(type1Object.Status)
{
  case SignStatusTypes.OK:
   // OK
   imgStatus = (int)ImageStatusTypes.OK;
   break;
  case SignStatusTypes.FAULTY:
   // FAULTY
   imgStatus = (int)ImageStatusTypes.FAULTY;
   break;
  case SignStatusTypes.UNKNOWN:
   // UNKNOWN
   imgStatus = (int)ImageStatusTypes.UNKNOWN;
   break;
}

ListViewItem lstvwItem1 = listView1.Items.Add("");
lstvwItem1.ImageIndex = imgStatus;
for(int i=0; i<mods; i++)
{
  if (i == 0)
  {
   lstvwItem1 = listView1.Items.Add(type1Object.Text0);
  }
  else if (i == 1)
  {
   lstvwItem1 = listView1.Items.Add(type1Object.Text1);
  }
  else if (i == 2)
  {
   lstvwItem1 = listView1.Items.Add(type1Object.Text2);
  }
  else if (i == 3)
  {
   lstvwItem1 = listView1.Items.Add(type1Object.Text3);
  }
}
}


private void AddType1ColumnsHeaders()
{
listView1.Columns.Clear();
listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
listView1.Columns.Add("Display", -2, HorizontalAlignment.Left);
}


Please can someone help!! Thanks in advance!
Author
18 Jan 2006 12:56 AM
Otis Mukinfus
Show quote Hide quote
On Tue, 17 Jan 2006 17:19:19 -0000, "WAkthar" <wakt***@hotmail.com>
wrote:

>Hi,
>
>I need to be able to display a listview with the following functionality.
>The listview must be able to display different types of information.
>There are normally 3 types.
>Type 1 has only 1 column.
>The first row must display an icon showing the status of this type.
>The following rows must display text messages.
>
>Type 2 has only 2 columns
>The first row, first column must display an icon showing the status of this
>type.
>The following rows, second column must display text messages.
>
>Type 3 is similar.
>
>Now for Type 1, I can get to display the icon but when I try to display
>messages in the next rows they appear in the second column!
>

You are adding all of your columns to the Items collection. Items
added to the Items collection are always shown in the fist column of
the listview.  To add the other columns you must add the items to the
subitems collection contained in each Item as shown below.

listView1.Items[0].SubItems.Add("John Smith");


Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Are all your drivers up to date? click for free checkup

Author
18 Jan 2006 11:47 AM
WAkthar
>
> You are adding all of your columns to the Items collection. Items
> added to the Items collection are always shown in the fist column of
> the listview.  To add the other columns you must add the items to the
> subitems collection contained in each Item as shown below.
>
> listView1.Items[0].SubItems.Add("John Smith");
>

But I would like to add items the first column.
So are you saying
Author
18 Jan 2006 11:48 AM
WAkthar
>
> You are adding all of your columns to the Items collection. Items
> added to the Items collection are always shown in the fist column of
> the listview.  To add the other columns you must add the items to the
> subitems collection contained in each Item as shown below.
>
> listView1.Items[0].SubItems.Add("John Smith");
>

I am trying to add only to the first column.
Are you saying that

lstvwItem1 = listView1.Items.Add(type1Object.Text0);

only adds to the first column in the listview ?
But when I run the app the items get added to the second column!
Author
19 Jan 2006 2:34 AM
Otis Mukinfus
Show quote Hide quote
On Wed, 18 Jan 2006 11:48:46 -0000, "WAkthar" <wakt***@hotmail.com>
wrote:

>
>>
>> You are adding all of your columns to the Items collection. Items
>> added to the Items collection are always shown in the fist column of
>> the listview.  To add the other columns you must add the items to the
>> subitems collection contained in each Item as shown below.
>>
>> listView1.Items[0].SubItems.Add("John Smith");
>>
>
>I am trying to add only to the first column.
>Are you saying that
>
>lstvwItem1 = listView1.Items.Add(type1Object.Text0);
>
>only adds to the first column in the listview ?
>But when I run the app the items get added to the second column!
>

Here is an example that I tried on my machine.  As you can see, I did
not use an icon.

            lv1.View = View.Details;
            lv1.Columns.Add("Item Column", 150, HorizontalAlignment.Left);
            lv1.Columns.Add("Column 0", 150, HorizontalAlignment.Left);
            lv1.Columns.Add("Column 1", 150, HorizontalAlignment.Left);
            lv1.Columns.Add("Column 2", 150, HorizontalAlignment.Left);
            lv1.Columns.Add("Column 3", 150, HorizontalAlignment.Left);
            ListViewItem item = lv1.Items.Add("Item Column");
            item.SubItems.Add("Column 0");
            item.SubItems.Add("column 1");
            item.SubItems.Add("Column 2");
            item.SubItems.Add("column 3");
HTH


Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Bookmark and Share