roujesky
asked on
Having trouble adding rows to DataGrid in WPF
I have create a DataGrid in WPF in XAML and now I want to add some rows. Here is the XAML Code segement
<DataGrid x:Name="DataGridResults" HorizontalAlignment="Left" Height="171" Margin="68,151,0,0" VerticalAlignment="Top" Width="715" Initialized="DataGridResul ts_Initial ized" SelectionChanged="DataGrid Results_Se lectionCha nged">
<DataGrid.Columns>
<DataGridTextColumn x:Name="ColumnMode" Header="Mode"/>
<DataGridTextColumn x:Name="ColumnCyan" Header="Cyan"/>
<DataGridTextColumn x:Name="ColumnMagenta" Header="Magenta"/>
<DataGridTextColumn x:Name="ColumnYellow" Header="Yellow"/>
<DataGridTextColumn x:Name="ColumnBlack" Header="Black"/>
<DataGridTextColumn x:Name="ColumnTotal" Header="Total" FontWeight="Bold"/>
<DataGridTextColumn/>
</DataGrid.Columns>
</DataGrid>
It has 6 columns.
I created a Class as
public class Cost
{
public string Mode { set; get; }
public Single Cyan { set; get; }
public Single Magenta { set; get; }
public Single Yellow { set; get; }
public Single Black { set; get; }
public Single Total { set; get; }
}
so, to add a row to the grid, i should just do
DataGridResults.Items.Add( new Cost() { Mode = "Test", Cyan = 0.025f, Magenta = .026f, Yellow = .027f, Black = .028f, Total = .198f });
DataGridsResult is my DataGrid....
I end up with a blank row. It adds the row, but not populated.
What am I missing?
thanks!
<DataGrid x:Name="DataGridResults" HorizontalAlignment="Left"
<DataGrid.Columns>
<DataGridTextColumn x:Name="ColumnMode" Header="Mode"/>
<DataGridTextColumn x:Name="ColumnCyan" Header="Cyan"/>
<DataGridTextColumn x:Name="ColumnMagenta" Header="Magenta"/>
<DataGridTextColumn x:Name="ColumnYellow" Header="Yellow"/>
<DataGridTextColumn x:Name="ColumnBlack" Header="Black"/>
<DataGridTextColumn x:Name="ColumnTotal" Header="Total" FontWeight="Bold"/>
<DataGridTextColumn/>
</DataGrid.Columns>
</DataGrid>
It has 6 columns.
I created a Class as
public class Cost
{
public string Mode { set; get; }
public Single Cyan { set; get; }
public Single Magenta { set; get; }
public Single Yellow { set; get; }
public Single Black { set; get; }
public Single Total { set; get; }
}
so, to add a row to the grid, i should just do
DataGridResults.Items.Add(
DataGridsResult is my DataGrid....
I end up with a blank row. It adds the row, but not populated.
What am I missing?
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER