|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
using listviewI 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!
Show quote
Hide quote
On Tue, 17 Jan 2006 17:19:19 -0000, "WAkthar" <wakt***@hotmail.com> You are adding all of your columns to the Items collection. Itemswrote: >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! > 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 > But I would like to add items the first 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"); > So are you saying > I am trying to add only to the first 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"); > 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!
Show quote
Hide quote
On Wed, 18 Jan 2006 11:48:46 -0000, "WAkthar" <wakt***@hotmail.com> Here is an example that I tried on my machine. As you can see, I didwrote: > >> >> 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! > 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
Other interesting topics
|
|||||||||||||||||||||||