1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
Hashtable[] data;
string[] fields;
string[] types;
// ... remplissage de 'data', 'fields' et 'types'
ListView listView = new ListView();
ArrayList arrayList = new ArrayList();
// création <GridViewColumn>
for (int i = 0; i < fields.Length; i++)
{
GridViewColumn gvc = new GridViewColumn();
Binding binding = new Binding(fields[i].ToUpper());
if ( types[i] == "date" ) binding.StringFormat = "dd/MM/yyyy HH:mm:ss";
gvc.DisplayMemberBinding = binding;
gvc.Header = fields[i];
gridView.Columns.Add(gvc);
}
// création <ListView.View>
listView.View = gridView;
// rajout des données
for (int i = 0; i < data.Length; i++)
{
DataObject dataObject = new DataObject();
for (int j = 0; j < fields.Length; j++)
{
dataObject.store(fields[j], data[i][fields[j]]);
}
arrayList.Add(dataObject);
}
listView.ItemsSource = arrayList;
public class DataObject
{
public string title;
public DateTime date;
public string photo;
public void store(string key, string value)
{
switch (key)
{
case "title":
title = value;
break;
case "date":
date = DateTime.ParseExact(value, "dd/MM/yyyy HH:mm:ss", new CultureInfo("fr-FR", true), DateTimeStyles.None);
break;
case "photo":
photo = value;
break;
}
}
public string TITLE
{
get { return this.title; }
}
public DateTime DATE
{
get { return this.date; }
}
public string PHOTO
{
get{ return this.photo; }
}
} |
Partager