So I have this array
string[,] cars = new String[2, 2] {
{ "VW Golf GTI", "30000" },
{ "Porsche GT3", "300000" },
{ "Porsche Cayenne", "80000" },
{ "BMW M6", "90000" }
};
And want to put everything in a listbox, and I thought this would work, but it doesn't :/
lstBoxMarket.Items.AddRange(cars);
Now how do I put everything in the listbox in the format
Car - Price ?
USE
DataSource
property to load data of multidimensional array.The better approach would be to Bind the ItemsSource to an ObservableCollection of a new class the data model Car type
Your view
.xaml
Your model Car.cs
Your view model will have a Collection that will be bound to ItemsSource
CarViewModel.cs
Try this:
Your version of
cars
will not currently compile as you are specifying constants for the array initializers (2 rows by 2 columns) but your data has 4 rows.