简体   繁体   中英

XamDataGrid - how to access the fields from code behind

I have a XamDataGrid which is being populated on a button click.

<Expander Header="{Binding Path=Tag, ElementName=EditGridExpanderBar}" Tag="Edit Grid" Visibility="Hidden"  Height="Auto" Name="EditGridExpanderBar" FontWeight="Bold" Background="#6688A4" Margin="0,0,5,3" Padding="3,0,0,0" Foreground="White">
    <igDP:XamDataGrid Name="EditGrid">
    </igDP:XamDataGrid>
</Expander>

Here is the code for populating the XamDataGrid.

private void EditAllocations_Click (object sender, RoutedEventArgs e)
{
    ObservableCollection<LobAllocation> ds = _controller.PlanitariumModel.Entity.LobAllocations;

    if (editGridClickCheck((Button)sender, ds.Count))
    {
        EditGrid.DataSource = ds;
    }
}

Here, the entity has some MetaData fields which are being displayed along with the actual columns in the Grid. I want to hide these fields manually.

Any pointers on how to do this?

You cannot hide specific fields. What you can do is switching off the auto column generation which is based on the public properties of the class which the datagrid is binding to. Also, you need to specify which properties should be displayed in the datagrid.

Try like this:

<igDP:XamDataGrid Name="EditGrid">
  <igDP:XamDataGrid.FieldLayouts>
    <igDP:FieldLayout>
      <igDP:Field Name="EntityProperty-1" Label="Property1" />
      <igDP:Field Name="EntityProperty-2" Label="Property2" />
   </igDP:FieldLayout>
 </igDP:XamDataGrid.FieldLayouts>

 <igDP:XamDataGrid.FieldLayoutSettings>
   <igDP:FieldLayoutSettings AutoGenerateFields="False"/>
 </igDP:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>

In the <igDP:FieldLayout> block you need to specify the columns of the Datagrid you want to present. With the following block you can disable the auto generation of the columns .

<igDP:XamDataGrid.FieldLayoutSettings>
   <igDP:FieldLayoutSettings AutoGenerateFields="False"/>
 </igDP:XamDataGrid.FieldLayoutSettings>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM