Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:37:35+00:00 2026-06-06T22:37:35+00:00

I’ve got a WPF DataGrid that I have been using for some time, and

  • 0

I’ve got a WPF DataGrid that I have been using for some time, and it works great. Unlike other posters here, I haven’t had issues with the scrollbar or mouse wheel (yet). I have CTRLEND programmed to go to the end of the DataGrid, and then it tracks the most-recently added items. I can scroll up through the DataGrid contents with the up key.

However, I have really weird behavior with the down key! If I start from the top of my DataGrid and hold the down key, it scrolls for a little bit and then eventually bounces back and forth between two adjacent rows. If I pgdn, it will scroll down more, then jump back to the topmost of the previous two rows that it would jump between, then scroll down to the point that I pgdn‘d to. If I page down some more, the down key will scroll to the end. If I go to the top of the DataGrid and start over, I get the exact same behavior, over and over again.

I’ve yet to find a post that addresses this, and I haven’t seen anything in the DataGrid documentation that helps.

It’s just a three-column DataGrid, where each column displays TextBlocks. Can anyone explain why just this one mode of scrolling is problematic? Here’s the XAML:

<DataGrid ItemsSource="{Binding MainLog}" AutoGenerateColumns="False" 
     Name="log_datagrid" SelectedCellsChanged="log_datagrid_SelectedCellsChanged"   
     KeyUp="datagrid_KeyUp" LoadingRow="log_datagrid_LoadingRow">
    <DataGrid.Columns>
        <!-- timestamp -->
        <DataGridTemplateColumn Header="Timestamp">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Timestamp}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <!-- level -->
        <DataGridTemplateColumn Header="Level">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Level}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <!-- error message -->
        <DataGridTemplateColumn Header="Message">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Message}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

By the way, this behavior occurs even with all of my code-behind for the event handlers commented out.

Here is the definition of the struct that my MainLog collection contains:

public struct MainLogData
{
    public string Timestamp { get; set; }
    public string Level { get; set; }
    public string Message { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:37:39+00:00Added an answer on June 6, 2026 at 10:37 pm

    Ok… I reproduced the behavior with strings (simple list of strings bound to the data grid). The behavior started happening when I introduced duplicates strings in my list. It seems that the data grid gets confused between the “selected index” and the “selected value”.
    The same kind of thing happens when I try to select a value (a string, in my test) that is present on another visible row: the selection gets screwed up: half of the time, the correct row is not selected.

    Your problem is that you are using a “struct”. The simple solution to your problem is to make your struct a class:

    public class MainLogData 
    { 
        public string Timestamp { get; set; } 
        public string Level { get; set; } 
        public string Message { get; set; } 
    }
    

    Just changing the struct word to class should fix your problem.

    You must understand that structs and classes are not the same, and structs determine their “equality” to another variable (with the same type) based on the values in them (2 variables of a specific structure type containing the same data will be considered equal). In the case of classes, unless specified otherwise, the equality is determined by its memory address; this ensures that by default no 2 instances of an object, even if they contain identical data, will not be considered equal because they do no reside at the same memory address (this behavior can be overwritten by overwriting “GetHashCode” and “Equals” methods in any class definition).

    So in conclusion, the DataGrid has problems determining which item your are selecting (or moving too with your arrow key) because many objects in your list are considered “the same”, or “equal”. That is why it gets confused. Admittedly, I think this is a datagrid bug (or at least stranger behavior if it is by design), but changing your data type from a struct to a class should help you get back on track!

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.