2 Replies - 3288 Views - Last Post: 08 August 2009 - 10:50 PM Rate Topic: -----

#1 iNutR  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 09-June 09

Listview Subitems index out of range

Posted 07 August 2009 - 07:47 PM

well im having listview problems.
my code is not letting me display a variable in listview subitem[3]
displaying the same varible in subitem[0] or [1] or [2] works fine, just 3 and onwards.

it says the index is out of range.

ive tried everything i can think of :S

heres my code:

		public void button1_Click(object sender, EventArgs e)
		{
			{

				int iCount = lvAccounts.Items.Count;

				ListViewItem[] accUserPass = new ListViewItem[iCount];
				lvAccounts.Items.CopyTo(accUserPass, 0);

				for (int i = 0; i < accUserPass.Length; i++)
				{

					foreach (ListViewItem item in lvAccounts.Items)
					{

// i defined my variables here

							accUserPass[i].SubItems[2].Text = sec;
							accUserPass[i].SubItems[3].Text = validpro;

						}
						
					}


ive manually defines column headers:

public RapidCheck()
		{
			InitializeComponent();
			lvAccounts.Columns.Add("Login", 80, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Password", 80, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Security", 75, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Expiry Date", 120, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Rapidpoints", 80, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Email", 80, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Ref Points", 80, HorizontalAlignment.Left);
			lvAccounts.Columns.Add("Files", 50, HorizontalAlignment.Left);
			
		
		}


still not working :S

please help

Is This A Good Question/Topic? 0
  • +

Replies To: Listview Subitems index out of range

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4356
  • View blog
  • Posts: 12,175
  • Joined: 18-April 07

Re: Listview Subitems index out of range

Posted 08 August 2009 - 12:17 PM

Can you show us where you have loaded up the data into lvwAccounts? The error is saying that each item in your listview only has three items (0, 1 and 2 index) so 3 doesn't exist. You did remember that indexes start at 0 right? So if you have three items it will be 0, 1, 2. Just thought I would double check that.

But anyways, you will need to show us how your data is loaded into the lvwAccounts listview because number of subitems isn't necessarily reflective of the number of columns you have created for the control.

Thanks! :)
Was This Post Helpful? 1
  • +
  • -

#3 iNutR  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 09-June 09

Re: Listview Subitems index out of range

Posted 08 August 2009 - 10:50 PM

yeh i found that out :D
after a while.
i just thought that having columns means that there are items declared :D
i guess not.
thanks alot :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1