I have an application which consumes several web services.
What I am trying to do is once this service is called, which should provide me with a list of project names, I would like to add them to one ListView
and that the user can choose which project to use.
When executing my code, I get the following error:
Additional information: InvalidArgument=Value of '0' is not valid for 'index'.
Here is my code, could you tell me how I can make it work?
ProjectMetaData[] pr = GetProjectMetaData();
foreach (ProjectMetaData proj in pr)
{
var listViewItem = new ListViewItem(proj.ProjectID);
listView1.Items.Add(listViewItem);
}
projectTitle = this.listView1.SelectedItems[0].Index.ToString();
the projectTitle variable is a getter outside of main:
string projectTitle { get; set; }
Thank you very much
In principle, your loading code
ListView
is correct:Then, if you want to detect when the user selects an element from the list, you would have to do something like this:
First, in the constructor of the
Form
subscribe eventSelectedIndexChanged
:And create a method like this: