I have a class “Seive”, a ObservableCollection seiveData object.
public Seive(String id)
{
SeiveIdSize = id;
Caret = 0.0;
Percent = 0.0;
Peices = 0;
Weight = 0.0;
Size = 0;
}
public String SeiveIdSize { get; set; }
public Double Weight { get; set; }
public Double Percent { get; set; }
public Double Caret { get; set; }
public uint Size { get; set; }
public uint Peices { get; set; }
In my xml : I have
<DataGrid Name="serverGrid" ItemsSource="{Binding}" .....>
<DataGrid.Columns>
<DataGridTextColumn Header="SEIVE" Width="Auto" Binding="{Binding Path=SeiveIdSize}" SortDirection="Ascending" />
<DataGridTextColumn Header="CTS" Width="Auto" Binding="{Binding Path=Caret}" />
<DataGridTextColumn Header=" % " Width="Auto" Binding="{Binding Path=Percent}" />
<DataGridTextColumn Header="PCS" Width="Auto" Binding="{Binding Path=Peices}" />
<DataGridTextColumn Header="WGT" Width="Auto" Binding="{Binding Path=Weight}" />
<DataGridTextColumn Header="SIZE" Width="Auto" Binding="{Binding Path=Size}" />
</DataGrid.Columns>
In window Loaded event, I fill 2 seives in seiveData, yet I don’t see any results/rows.
seivesData.Add(new Seive("+10"));
seivesData.Add(new Seive("+8"));
seivesDataGrid.DataContext = seivesData;
EDIT :
Button Event Code :
private void saveBtn_Click(object sender, RoutedEventArgs e)
{
Seive s1 = new Seive("+2");
s1.Peices = 100;
s1.Caret = 0.41;
s1.Weight = 0.10;
seivesData.Add(s1);
Seive s = seivesData[0];
s.Caret = 0.54;
s.Weight = 0.32;
seivesData[0] = s;
seiveDG.DataContext = seivesData;
}
Where am I going wrong ? I can see the newly added Seive all details, but Not the Caret & Weight added to 0th seive.
The basic problem i see in your xaml is that you set the ItemsSource = {binding SeiveData}
which is wrong if your pass this property into data context of the grid.
This below code is working now. check it.
one more thing if your want to notify the chagnes into the class Seive then must implement the INotifyPropertyChange interface.
XAML
Cose behind
class