I've created two columns on the list view as follows.
Code:
ColumnHeader colHed;
// Header one
colHed = new ColumnHeader();
colHed.Text = "Name";
colHed.Width = 100;
this.lwDetails.Columns.Add(colHed);
// Header two
colHed = new ColumnHeader();
colHed.Text = "Address";
colHed.Width = 200;
this.lwDetails.Columns.Add(colHed);
Then on a separate function I try to add data to those columns. Name and address of a one person store in a string array named items. I try to add data as follows.
// load some data
ListViewItem lvwItem;
lvwItem =this.lwDetails.Items.Add(new ListViewItem("Test1"));
lvwItem.SubItems.Add("SubItem1");
lvwItem = this.lwDetails.Items.Add("Test2");
lvwItem.SubItems.Add("SubItem2");
I'm not clear what happened on this code, I mean how to find the "Name" column to add the relevant data to it. And "Address" column also. Can you explain it little more.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
"SubItem1" and "SubItem2" are the text of the subitems being added.
By setting the lvwItem object to the resulting .Add of the new listviewitem we get a object reference set to that exact item/row. Using the object variable we can access the properties and methods of the row. .SubItems.Add is the method for adding new subitems/text to the other secondary columns.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Yes that is true but I was doing it for a demo and as its my preference to code in the setup of the controls instead of property wwindow property setting changes. Explicit code setup is just a matter of personal preference.
That link goes back to your original post?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.