Selecting WPF ListView row in code

An app I am considering migrating to WPF uses a DevExpress grid to show a list of events, as I animate my composition I highlight the current event in the grid. Things I have learned about WPF:

01: You can create a data grid type view like so:
<ListView Name="ListView">
    <GridView AllowsColumnReorder="False">
      <GridViewColumn DisplayMemberBinding="{Binding Path=Title}" Header="Title"/>
      <GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}" Header="FirstName"/>
      <GridViewColumn DisplayMemberBinding="{Binding Path=LastName}" Header="LastName"/>

02: Don’t put a ListView in a <StackPanel>! It renders all of the data at once. When you have 6K rows of data for example it takes about 1 second to select the next row. Instead you should put it in a grid

    <RowDefinition Height="50"/>
    <RowDefinition Height="*"/>

  <Button Grid.Row="0"…../>
  <ListView Grid.Row="1"…../>

03: When selecting a row in code the row does not become visible. To automatically make the row visible you need to use ScrollIntoView()


2 thoughts on “Selecting WPF ListView row in code

  1. Hi,

    Is it possible to scroll the item into view such that it is shown in the middle of all VISIBLE records, instead of on the top.

Leave a Reply

Your email address will not be published. Required fields are marked *