Reputation: 13
I'm looking to create a graph from items in a listView, I think I need to copy these items into an array and then go from there.
The 2 columns I want to plot against each other are; 'Power' (double) and 'Duration' (TimeSpan), any thoughts on how to go about doing this?
note: the listView has 3 columns; Device, Power, Duration. The user can fill the listView with as many devices as they desire
Upvotes: 0
Views: 1926
Reputation: 1022
To get all the records into an array, you can use this:
ListViewItem[] items = new ListViewItem[listView1.Items.Count];
listView1.Items.CopyTo(items, 0);
If you really only want the Power and Duration, you will need to loop over every row in the ListView and then you can get the subItems by using:
listView1.Items[i].SubItems;
Also, what i would do, is make a struct to store the 2 values, and add those structs to a list, but that requires(i think) to loop trough the array to fill all the structs. Anyway, like this:
struct Row{
public double Power { get; set; }
public TimeSpan Duration { get; set; }
}
Upvotes: 1