Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,

whenever i try to get the index of the selected item from the listview , for the first time the index gets selected but second time whenever i select some particular item from listview then error occurs stating "Invalid argument , value of 0 is not valid for index "


I mean to say one time selection is possible but second time i cannot select the item from the listview..



For instance ... I took a listview control on a on the form ... put 3 items hi , hello , world ... now i put a statement
MessageBox.Show("selected index is " +listView1.SelectedIndices[0] ); on the selectedindexchanged event so whenever i select an item messagebox does come but next time whenever i select any other item an error flashes stated .."InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index"


I mean to say that i want that i can select any number of times a single item from the listview .



CAN anybody help me with that ....
Posted
Updated 20-Sep-11 22:58pm
v5

1 solution

C#
//Assign few data on OnInit to the List
BOOL CLEDDlg::OnInitDialog()
{
m_ctrlListData.AddString("Red");
m_ctrlListData.AddString("Blue");
m_ctrlListData.AddString("Yellow");
...
...
}
/// Write the below code on click of a button

CLEDDlg::OnButton()
{
int n = m_ctrlListData.GetCurSel();
CString szTemp;
szTemp.Format("%d",n);
AfxMessageBox(szTemp);// to display the index selected
}


Please write back if this is what you needed.
 
Share this answer
 
v3
Comments
iampradeepsharma 21-Sep-11 1:55am    
well i guess this code is MFC code ....but i tried similar task in csharp but same errors occurs ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900