Click to See Complete Forum and Search --> : Listview in WIndows Form App.


BilginCetin
August 6th, 2004, 03:13 AM
hi. i wanna add some data to listview.i can add colomns rows but subitems exept first row.i can add subitems to first row but the others.the function i use is:
listView1->Items->Item[0]->SubItems->Add(ItemObject2[1]);
i tried to use:
listView1->Items->Item[1]->SubItems->Add(ItemObject2[1]);but it gives an error like, argument was out of the range of valid values.here is part of my code:

while (myDataReader->Read())
{
ListViewItem *items = new ListViewItem(S"helal",0);

ItemObject2[0] = String::Concat(S"", myDataReader->GetValue(0));
ItemObject2[1] = String::Concat(S"", myDataReader->GetValue(1));
ItemObject2[2] = String::Concat(S"", myDataReader->GetValue(2));

listView1->Items->Add(ItemObject2[0],3);
listView1->Items->Item[0]->SubItems->Add(ItemObject2[1]);
listView1->Items->Item[0]->SubItems->Add(ItemObject2[2]);

//listView1->Items->Item[1]->SubItems->Add(ItemObject2[2]);
}

thanks..

JetDeveloper
August 7th, 2004, 12:52 AM
You need to add an item at each index before you can add any subitems to it.


int count = 0;
while (myDataReader->Read())
{
ListViewItem *items = new ListViewItem(S"helal",0);

ItemObject2[0] = String::Concat(S"", myDataReader->GetValue(0));
ItemObject2[1] = String::Concat(S"", myDataReader->GetValue(1));
ItemObject2[2] = String::Concat(S"", myDataReader->GetValue(2));

listView1->Items->Add(ItemObject2[0],3);
listView1->Items->Item[count]->SubItems->Add(ItemObject2[1]);
listView1->Items->Item[count]->SubItems->Add(ItemObject2[2]);

count++;
}

BilginCetin
August 9th, 2004, 02:47 AM
thanks, really!