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
990
DataRecordPresenter.FromRecord() returns null for not viewable records
posted

Hi, 

I found a hurdle in my work..

Say I have 100 records in Xamdatagrid and its size is such that you can see only 25 records, (you can see all the records when you scroll.).. Please do not scroll and change the background color of all the records on button click.

You will find that DataPresenter will be NOT NULL for those 25 records and will be NULL for other 75records. 

 

  •         RecordPresenter recordPresenter = DataRecordPresenter.FromRecord(dataRecord);
  •         if (recordPresenter == null)
  •           recordPresenter = new DataRecordPresenter();

 

Note :-   If (recordPresenter == null) recordPresenter = new DataRecordPresenter();  this also not worked.

I sent you my code.. please check.


XAML

 <DataPresenter:XamDataGrid  GroupByAreaLocation="None" Theme="Office2k7Black" x:Name="_gridCounterParty" DataSource="{Binding Path=SelectedCounterparties}" RecordActivated="_grid1_RecordActivated">

                    <DataPresenter:XamDataGrid.Resources>

                        <Style x:Key="_deleteCellValuePresenter" TargetType="{x:Type DataPresenter:CellValuePresenter}">

                            <Setter Property="Template">

                                <Setter.Value>

                                    <ControlTemplate TargetType="{x:Type DataPresenter:CellValuePresenter}">

                                        <Button Width="{TemplateBinding ActualWidth}" Tag="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Record.DataItem}" Click="_deleteButton_Click"  x:Name="_deleteButton" Content="X"/>

                                    </ControlTemplate>

                                </Setter.Value>

                            </Setter>

                        </Style>

                    </DataPresenter:XamDataGrid.Resources>

                    <DataPresenter:XamDataGrid.FieldLayoutSettings>

                        <DataPresenter:FieldLayoutSettings AutoFitMode="Always"/>

                    </DataPresenter:XamDataGrid.FieldLayoutSettings>

                    <DataPresenter:XamDataGrid.FieldLayouts>

                        <DataPresenter:FieldLayout x:Name="_accountdetailFieldLayout">

                            <DataPresenter:Field Name="Account" Width="200*"/>

                            <DataPresenter:Field Name="Name" Width="800*" />

                            <DataPresenter:UnboundField x:Name="_Delete" Width="50*">

                                <DataPresenter:UnboundField.Settings>

                                    <DataPresenter:FieldSettings AllowRecordFiltering="False" CellValuePresenterStyle="{StaticResource _deleteCellValuePresenter}"/>

                                </DataPresenter:UnboundField.Settings>

                            </DataPresenter:UnboundField>

                        </DataPresenter:FieldLayout>

                    </DataPresenter:XamDataGrid.FieldLayouts>

                    <DataPresenter:XamDataGrid.FieldSettings>

                        <DataPresenter:FieldSettings FilterOperatorDefaultValue="Contains" FilterStringComparisonType="CaseInsensitive"  AllowRecordFiltering="True"/>

                    </DataPresenter:XamDataGrid.FieldSettings>

                </DataPresenter:XamDataGrid>

 

Code Behind

foreach (Record dataRecord in _gridCounterParty.Records)

      {

        _gridCounterParty.UpdateLayout();

        LimitAccountSearchResult counterparty = (dataRecord as DataRecord).DataItem as LimitAccountSearchResult;

        RecordPresenter recordPresenter = DataRecordPresenter.FromRecord(dataRecord);

        if (recordPresenter == null)

          recordPresenter = new DataRecordPresenter();

        if (accountErrorInfo.Keys.Contains("FAILED") && accountErrorInfo["FAILED"].ContainsKey(counterparty.Account))

        {

          recordPresenter.Background = Brushes.Red;

          recordPresenter.ToolTip = accountErrorInfo["FAILED"][counterparty.Account];

          recordPresenter.BorderThickness = new Thickness(2);

        }

        else if (accountErrorInfo.Keys.Contains("SUCCESS") && accountErrorInfo["SUCCESS"].ContainsKey(counterparty.Account))

        {

          recordPresenter.Background = Brushes.Green;

          recordPresenter.ToolTip = accountErrorInfo["SUCCESS"][counterparty.Account];

          recordPresenter.BorderThickness = new Thickness(2);

        }

      }