WPF DataGrid Binding List<List<class>>

A

Anders Eriksson

I have this class

public class Note
{
public string Name { get; set; }
public int Octave { get; set; }
public int Midi { get; set; }
}

Using this I can create an collection List<List<Note>> Fretboard;
(Short explanation: I want to represent a Guitar Fretboard, which has
multiple string with multiple frets each having a Note)

Which I fill with the wanted values. The list is a read only so there is
no need for notifying any change, since there will not be any...
This part works well!

Now I want to bind the collection to a DataGrid (in WPF).


<Window x:Class="NotesOnFretboard.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False"
Margin="12,53,12,29" Name="dataGrid1" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" />
</Grid>
</Window>

Connecting the Fretboard to dataGrid1
dataGrid1.DataContext = Fretboard;

I have two problems:
1. The datagrid is populated but with nothing. I just get the lines for
each row.
2. I want to be able to let the user select which value that should be
shown in the DataGrid. It could be Name, Octave, Name+Octave, or Midi

Please Help!


// Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top