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
530
Hide specific cell in xamdatagrid.
posted

I have a xamdata grid, and I want to hide my template field for the first row. 

To elaborate, lets say I have this data grid. 

<igDP:XamDataGrid x:Name="DataGrid" BindToSampleData="True" AutoFit="True">
    <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
            <igDP:FieldLayout.Fields>
                <igDP:TextField Name="name"/>
                <igDP:TextField Name="department"/>
                <igDP:TextField Name="email" Visibility="Collapsed" />
                <igDP:TemplateField Name="salary" >
                    <igDP:TemplateField.DisplayTemplate>
                        <DataTemplate>
                            <TextBlock Text="{igEditors:TemplateEditorValueBinding}"
                                       HorizontalAlignment="Right"/>
                        </DataTemplate>
                    </igDP:TemplateField.DisplayTemplate>
                    <igDP:TemplateField.EditTemplate>
                        <DataTemplate>
                            <Border BorderBrush="LightGreen" BorderThickness="1">
                                <igEditors:XamNumericEditor Value="{igEditors:TemplateEditorValueBinding}"                                    SpinButtonDisplayMode="Always" SpinIncrement="50"/>
                            </Border>
                        </DataTemplate>
                    </igDP:TemplateField.EditTemplate>                                             </igDP:TemplateField>
            </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
    </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Re

I want to hide the "salary" column, for the first row only. The first row should have an empty cell.

It should be regular for the rest of the inputs. 

How can I achieve that ?

  • 34830
    Offline posted

    Hello Guray,

    In order to have a “hidden” column in the first row only, I would recommend having the underlying data be blank for the first item in your data source for the corresponding “salary” property. For example, if your “salary” item is a double, you can pass double.NaN for the salary property. Alternatively, you could use a nullable double (double?) and pass null.

    I also find it likely that you will want to prevent the first cell from going into edit mode to prevent the EditTemplate from appearing. In order to do this, I would recommend handling the EditModeStarting event of the XamDataGrid. This event is cancellable, and from the event arguments, you can obtain the Cell that is trying to go into edit mode. From that Cell, you can get the underlying Record as well as the Field that the Cell belongs to, and in checking these things, you prevent the first record for a particular Field from going into edit mode.

    Please let me know if you have any other questions or concerns on this matter.