Welcome to the Xceed Community | Help
Community Search  
More Search Options

Unexpected BringItemIntoView behaviour

Sort Posts: Previous Next
  •  12-09-2009, 3:40 PM Post no. 25132

    Unexpected BringItemIntoView behaviour

    Hi

     I have a grid, which is bound to a simple BindingList, with time and status as the two variables, both strings. When I add to the underlying data I want the grid to scroll to the bottom of the data. I have the following code, which I thought would work, based on some of the posts I have read here, but I just can't get it to behave.

    The grid sometimes shows the last item part way up the grid, with empty space below, sometimes as the only entry in the grid, i.e. at the top with loads more space below. I've posted the XAML for the grid too. Is there something I'm missing ??

    If I have the MS WPF Datagrid I just need the following command and it works a treat: statusGrid.ScrollIntoView(statusGrid.Items[statusGrid.Items.Count - 1]);

    Any help would be appreciated, thanks, Mike...

    BTW I have v3.2 standard

    Code:

    public void Logger(string updateWith)
    {
      DateTime itisNow = DateTime.Now;
      logthis.Add(new LogClass { LogTime = itisNow.ToString(), LogData = updateWith });

      if (statusGrid.Items.Count > 8)  //Only Scroll when more than 8 items are in the data. Remember grid is fixed size.
      {
        statusGrid.SelectedItems.Clear();
        statusGrid.SelectedItem = statusGrid.Items[statusGrid.Items.Count - 1];
        statusGrid.BringItemIntoView(statusGrid.SelectedItem);
        statusGrid.SelectedItem = null;
      }
    }

    <xcdg:DataGridControl x:Name="statusGrid" ItemsSource="{Binding}" ReadOnly="True" EditTriggers="None" SelectionMode="Single" NavigationBehavior="RowOnly" ItemScrollingBehavior="Immediate" Height="110" FontSize="10" Foreground="DarkOliveGreen" Background="Black" Grid.RowSpan="2" BorderThickness="0">

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName="LogTime" ReadOnly="True" ShowInColumnChooser="False" Title="Time" />

    <xcdg:Column FieldName="LogData" IsMainColumn="True" ReadOnly="True" ShowInColumnChooser="False" Title="LogEntry" />

    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.Resources>

    <Style x:Key="{x:Type xcdg:ScrollTip}" TargetType="xcdg:ScrollTip">

    <Setter Property="HorizontalAlignment" Value="Right" />

    <Setter Property="VerticalAlignment" Value="Center" />

    </Style>

    </xcdg:DataGridControl.Resources>

    <xcdg:DataGridControl.View>

    <xcdg:TableView ShowFixedColumnSplitter="False" ColumnStretchMode="Last" ShowRowSelectorPane="False" IsAlternatingRowStyleEnabled="False" UseDefaultHeadersFooters="False" ShowScrollTip="True">

    <xcdg:TableView.FixedHeaders>

    <DataTemplate>

    <xcdg:ColumnManagerRow AllowSort="False" AllowColumnReorder="False" AllowColumnResize="False" AllowAutoFilter="False" />

    </DataTemplate>

    </xcdg:TableView.FixedHeaders>

    <xcdg:TableView.Theme>

    <xcdg:AeroNormalColorTheme />

    </xcdg:TableView.Theme>

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

    </xcdg:DataGridControl>

  •  12-09-2009, 3:43 PM Post no. 25133 in reply to 25132

    Re: Unexpected BringItemIntoView behaviour

    Oh, I have also tried the post with the following code:

    var grid = VisualTreeHelper.GetChild(statusGrid, 0);

    var border = (Decorator)VisualTreeHelper.GetChild(grid, 0);

    var scroll = (ScrollViewer)(((Decorator)border.Child)).Child;

    scroll.ScrollToVerticalOffset(scroll.ExtentHeight - scroll.ViewportHeight);

    When it hits the 3rd line I get an unhandled exception "when casting from a number, the value must be a number less than infinity". To be honest I don't really understand the code, to start trying to debug it.

    Cheers, Mike...

  •  03-16-2010, 9:55 AM Post no. 26118 in reply to 25133

    Re: Unexpected BringItemIntoView behaviour

    Hi Mike,

     I had had a similar problem. Take a look at the post with a code sample. The idea behind is not to use BringItemToView, but to set the CurrentItem property.

     Hope this helps.

     Cheers!

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.