I’ve been trying to do this for a long time now without success.
I am trying to store a Dictionary in a GridView in WPF. I am able to store the Keys/Values, but unable to get the values of specific keys. For example, in the example below I would like to retrieve the value for the key “1” (which is “4”). No success yet with TryGetValue.
This is my code:
public MainWindow()
{
InitializeComponent();
McDataGrid.ItemsSource = files.Keys;
}
Dictionary<Files, string> files = new Dictionary<Files, string>();
public class Files
{
public string File { get; set; }
public string Duration { get; set; }
public string Status { get; set; }
}
private void AddFilesList(string addsrc, string addduration, string addstatus, string path)
{
files.Add(new Files
{
File = addsrc,
Duration = addduration,
Status = addstatus
}, path
);
DataGrid.Items.Refresh();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
AddFilesList("1", "2", "3", "4");
}
Try this code