Link to home
Start Free TrialLog in
Avatar of roujesky
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="DataGridResults_Initialized" SelectionChanged="DataGridResults_SelectionChanged">
            <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!
Avatar of roujesky
roujesky

ASKER

it seems weird, because it created a row, but it is not populated.  it is an empty row....
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial