This is a migrated thread and some comments may be shown as answers.

Strange scrolling behavior in RadGridView

0 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 15 Jun 2012, 05:32 PM
I have a form with a couple of RadGridView controls on it.  The form in question is a UserControl, embedded in a TabItem in a TabControl on the MainWindow.  There is another UserConrol on another TabItem in the same TabControl, which is used to display details of the selected item in one of the RadGridView controls, and other that is used to display the details of the selected item in the other RadGridView.

Here is the Xaml for one of the RadGridView controls:
<telerik:RadGridView AutoExpandGroups="True"
                     AutoGenerateColumns="False"
                     CanUserDeleteRows="False"
                     CanUserFreezeColumns="False"
                     CanUserInsertRows="False"
                     CanUserResizeColumns="True"
                     CanUserSortColumns="True"
                     EnableColumnVirtualization="True"
                     EnableRowVirtualization="True"
                     FontSize="16"
                     FontWeight="Bold"
                     IsReadOnly="True"
                     MouseDoubleClick="ReadsGrid_MouseDoubleClick"
                     Name="ReadsGrid"
                     RowStyleSelector="{StaticResource StyleSelector}"
                     SelectionChanged="ReadsGrid_SelectionChanged"
                     SelectionUnit="FullRow"
                     ScrollViewer.CanContentScroll="True"
                     ScrollViewer.HorizontalScrollBarVisibility="Auto"
                     ScrollViewer.VerticalScrollBarVisibility="Auto"
                     ShowGroupFooters="True"
                     ToolTip="Matching Reads">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Plate,       Mode=OneWay}"
                                    Header="Plate"
                                    Width="*" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding State,       Mode=OneWay}"
                                    Header="State"
                                    Width="75" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding TimeStamp,  Mode=OneWay, Converter={StaticResource DateConverter}}"
                                    Header="Date & Time"
                                    Width="175" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding GPSInformation.Position.Latitude, Converter={StaticResource CoordConverter}, ConverterParameter=NS}"
                                    Header="Latitude"
                                    Width="142" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding GPSInformation.Position.Longitude, Converter={StaticResource CoordConverter}, ConverterParameter=EW}"
                                    Header="Longitude"
                                    Width="142" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

From the code-behind, here is the code for the SelectionChanged event handler and for the MouseDoubleClick event handler:
private void ReadsGrid_MouseDoubleClick( object sender, MouseButtonEventArgs e ) {
    if ( OkToSwitchToRecordDetails ) {
        TabItem searchTabItem = (TabItem) Parent;
        TabControl tabControl = (TabControl) searchTabItem.Parent;
        TabItem recordDetailsTabItem = FindTab( typeof( EditRecordDetails ) );
        recordDetailsTabItem.IsSelected = true;
    }
    e.Handled = true;
}
private void ReadsGrid_SelectionChanged( object sender, SelectionChangeEventArgs e ) {
    ReadViewModel read = (ReadViewModel) ReadsGrid.SelectedItem;
    ReadsGrid.ScrollIndexIntoView( ReadsGrid.Items.IndexOf( read ) );
    HavePrevRecord = ReadsGrid.Items.IndexOf( read ) > 0;
    HaveNextRecord = ReadsGrid.Items.IndexOf( read ) < ( Reads.Count - 1 );
    RecordDetailsControl.DisplayRead( read );
    e.Handled = true;
}

Everything works, but there's something very odd going on.  When you double click on the row, the RadGridView seems to scroll.  In fact, it scrolls far enough to bring the row you just double clicked on off the screen. Note that the call to ScrollIndexIntoView has no effect:  I added that to try to bring the row back into view and it's doing nothing.

In the UserControl in the other tab, there are two buttons named "PrevButton" and "NextButton".  Here is the code for their Click event handlers:
private void NextButton_Click( object sender, RoutedEventArgs e ) {
    try {
        SearchControl.NextRecord( LastRecord );
    } catch ( ObjectNotFoundException ex ) {
        string msg = MessageGenerator.ExceptionMessage( "Error getting next record: ", ex );
        Log.Error( msg );
        CarSystemMessageBox.Show( msg, "Error Getting Next Record" );
    }
    // Mark event handled
    e.Handled = true;
}
private void PrevButton_Click( object sender, RoutedEventArgs e ) {
    try {
        SearchControl.PrevRecord( LastRecord );
    } catch ( ObjectNotFoundException ex ) {
        string msg = MessageGenerator.ExceptionMessage( "Error getting next record: ", ex );
        Log.Error( msg );
        CarSystemMessageBox.Show( msg, "Error Getting Next Record" );
    }
    // Mark event handled
    e.Handled = true;
}

And here's the NextRecord and PrevRecord methods in the SearchControl:

public void NextRecord( ReadViewModel read ) {
    // Figure out the index of the last object in the ReadsGrid RadGridView's Items collection
    int lastObj = ReadsGrid.Items.Count - 1;
    // Get the index of this object in the ReadsGrid's Items collection.
    int idxRead = ReadsGrid.Items.IndexOf( read );
    // The next record is the next one in the ReadsGrid's Items collection, if there is one.
    if ( idxRead < lastObj ) {
        // Set HaveNextRecord and HavePrevRecord
        HavePrevRecord = true;
        HaveNextRecord = idxRead < lastObj;
        // Select the next record.
        read = ReadsGrid.Items[ idxRead + 1 ] as ReadViewModel;
    } else {
        // There isn't a next record.  Set HaveNextRecord and HavePrevRecord
        HaveNextRecord = false;
        HavePrevRecord = idxRead > 0;
    }
    // Select the Read & scroll it into view
    ReadsGrid.SelectedItem = read;
    ReadsGrid.ScrollIntoView( read );
}
public void PrevRecord( ReadViewModel read ) {
    // Declare some variables we will need to use
    int idxRead  = -1;
    // Get the index of this object in the ReportRows array.
    idxRead = ReadsGrid.Items.IndexOf( read );
    // The previous record is the previous one in the ReadsGrid's Items collection, if there is one.
    if ( idxRead > 0 ) {
        // Set HaveNextRecord and HavePrevRecord
        HaveNextRecord = true;
        HavePrevRecord = idxRead > 0;
        // Select the next record.
        read = ReadsGrid.Items[ idxRead - 1 ] as ReadViewModel;
    } else {
        // There isn't a previous record.  Set HavePrevRecord to false and HaveNextRecord
        HavePrevRecord = false;
        HaveNextRecord = idxRead < ( ReadsGrid.Items.Count - 1 );
    }
      
    // Select the Read & scroll it into view
    ReadsGrid.SelectedItem = read;
    ReadsGrid.ScrollIntoView( read );
}

Again, everything works, but the ScrollIntoView doesn't work.  I've always had that call there, in case you kept clicking one of the buttons and eventually selected a row that wasn't in view.

All rows are the same height, and turning RowVirtualization off has no effect.  The rows are still off the screen when I come back to the tab with the RadGridViews.

Is this a bug? Is there some property I have turned on that's breaking it?

Tony

P.S.  I am using version 2012.1.326.40

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Tony
Top achievements
Rank 1
Share this question
or