Doro
Doro

Reputation: 671

Add image in arraylist

I have to create a WPF app. which collects strings and images in rows. I am not sure if I could use multidimedional array or ArrayList but I cannot figure out how to insert the image into the array. Anyone can help me?

Upvotes: 0

Views: 476

Answers (1)

Viv
Viv

Reputation: 17388

So if you want 1 Image against a variable number of string's

your Image becomes the Key of the Dictionary and the List<string> it's corresponding Value.

public Dictionary<Image, List<string>> MyCollection { get; private set; }

...
// Initialisation
MyCollection = new Dictionary<Image, List<string>>();

// Adding new Row
var tempImage = new Image();
MyCollection.Add(tempImage, new List<string>(){"A", "B", "C"});

// Modifying existing row -- for `Key` tempImage we'll add a string "D" and remove string "A"
List<string> existingValues = MyCollection[tempImage];
existingValues.Add("D");
existingValues.Remove("A");

// Removing rows
MyCollection.Remove(tempImage);

You can download this sample from Here. Hope that clarifies some of the usage ideas. I'd suggest looking at some Simple Examples to get a better understanding of how you can use Dictionary<...> to achieve your requirements.

Upvotes: 1

Related Questions