So, I'm trying to implement a ComboBoxColumn but it's not saving the data unlike when I edit the other elements. I can choose the elements inside the ComboBox during run but it's not being saved. Even sorting the other rows makes the ComboBox empty again.
XAML:
...
<DataGridComboBoxColumn x:Name="ColSID" Header="Guild"
SelectedValueBinding="{ Binding Guilds, Mode=TwoWay }"
ItemsSource="{Binding Guilds}"
SelectedValuePath="SID"
DisplayMemberPath="Name"
CanUserSort="False" />
...
Here is the Guild class:
public class Guild
{
public string SID { get; set; }
public string Name { get; set; }
}
Initializing via:
Guilds = new List<Guild>();
Guilds.Add(new Guild { SID="1", Name="Test Server x1" });
Guilds.Add(new Guild { SID="2", Name="Test Server x2" });
ColSID.ItemsSource = Guilds;
The DataTable is stored into a JSON file as soon as a cell is changed:
DataTable dt = ((DataView)senderDataGrid.ItemsSource).ToTable();
using (StreamWriter file = File.CreateText(filename))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, dt);
}