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
140
Get cell value in XamGrid
posted

Hi, I have XamGrid with binding to the DataTable. This is because i need to create columns dynamically. Each cell should contain individual class and i need access to its properties that are different for each cell except for one property that is same in one row and one property that is same in one column. Example: The different properties for each cell are Name and Value, Date is same for each row, Type is same for each column.

Example table

I used XamDataGrid before and to get value of single cell i used this (there are more textboxes in a single cell):

<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="cellTemplate" x:Name="cellTemplate" >
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                            <Border>
                                <Border.ToolTip>
                                    <StackPanel>
                                        <TextBlock Text="Database Value:"/>
                                        <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value.DBValue}"/>
                                    </StackPanel>
                                </Border.ToolTip>
                                <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                                    <TextBlock Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value.DateHolder, Converter={StaticResource VisibilityConverter}}" 
                                               Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}, Path=Value.Date}" />
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

<igDP:XamDataGrid Grid.Row="1" DataSource="{Binding Path=ImportData.DefaultView}" ScrollingMode="Immediate" AutoFit="True" GroupByAreaLocation="None">
            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings CellValuePresenterStyle="{StaticResource cellTemplate}" CellClickAction="SelectCell" />
            </igDP:XamDataGrid.FieldSettings>
        </igDP:XamDataGrid>

Is something like this possible with XamGrid? I tried this but i get whole row in converter and i don't know how to address individual cell in that row.

<Style x:Key="CellStyle" TargetType="ig:CellControl">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ig:CellControl">
                            <TextBlock Text="{Binding Converter={StaticResource converter}}" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

 <ig:XamGrid Grid.Row="2" ItemsSource="{Binding Path=ImportData.DefaultView}" CellStyle="{StaticResource CellStyle}"></ig:XamGrid>

Reason for changing XamDataGrid for XamGrid is selection possibilities with XamGrid. In XamDataGrid I can't select individual cells by clicking and draging like in XamGrid. I am using MVVM so events may be problem. It would be better for me to use converters and bindings, triggers, styles etc. Source data don't have to be in form of DataTable. I can load it to almost everything (arrays, lists, expandoObjects,...). Thank you for any advice.

Lukas