Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1655
Dynamically Add rows to the Grid
posted

Hi,

I am trying to add a row to the grid through code on click of a button. But, the grid is showing as blank cells.

Can you tell me what mistake i am doing. The code is below.

 

XAML

<igDP:XamDataGrid Name="dgDet" Grid.Row="2"
                                      Grid.ColumnSpan="9" TabIndex="59" Width="Auto"
                                      GroupByAreaLocation="None"
                                      HorizontalAlignment="Center">
                        <igDP:XamDataGrid.Resources>
                            <Style TargetType="{x:Type igDP:CellValuePresenter}">
                                <Setter Property="HorizontalContentAlignment" Value="Center" />
                            </Style>
                        </igDP:XamDataGrid.Resources>
                        <igDP:XamDataGrid.FieldLayoutSettings>
                            <igDP:FieldLayoutSettings AutoGenerateFields="False"
                                                      HighlightAlternateRecords="True" />
                        </igDP:XamDataGrid.FieldLayoutSettings>
                        <igDP:XamDataGrid.FieldLayouts>
                            <igDP:FieldLayout>
                                <igDP:FieldLayout.Fields>
                                    <igDP:UnboundField Name="EmpID" Label="Emp ID">
                                        <igDP:Field.Settings>
                                            <igDP:FieldSettings AllowEdit="False"
                                                LabelTextAlignment="Center"/>
                                        </igDP:Field.Settings>
                                    </igDP:UnboundField>
                                    <igDP:UnboundField Name="FirstName" Label="First Name">
                                        <igDP:Field.Settings>
                                            <igDP:FieldSettings AllowEdit="False"
                                                LabelTextAlignment="Center"/>
                                        </igDP:Field.Settings>
                                    </igDP:UnboundField>
                                    <igDP:UnboundField Name="LastName" Label="Last Name">
                                        <igDP:Field.Settings>
                                            <igDP:FieldSettings AllowEdit="False"
                                                LabelTextAlignment="Center"/>
                                        </igDP:Field.Settings>
                                    </igDP:UnboundField>
                                </igDP:FieldLayout.Fields>
                            </igDP:FieldLayout>
                        </igDP:XamDataGrid.FieldLayouts>
                    </igDP:XamDataGrid>

 

Code behind:

private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Employee employeeDet = new Employee();
            employeeDet .EmpID = "A123";
            employeeDet .FirstName = "Varun";
            employeeDet .LastName = "R";
            this.dgDet.DataItems.Add(employeeDet );
        }

Here Employee is an entity class.

 

Thanks,

Varun