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
What a silly mistake from me :P
Hello Varun,
You are using UnboundFields, so they are not bound to the DataSource of the XamDataGrid ( as their name implies) and that is why they are not displaying any data. You have to bind them by setting their BingingPath properties to the corresponding properties of the Employee object like this:
BindingPath="EmpID"
BindingPath="FirstName"
BindingPath="LastName"