Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataGrid: Show row index and reset sorting

$
0
0

I am a WPF-noob and have two DataGrid problems:

Problem 1:

What I got: A DataGird that gets its data from a array:

<DataGrid x:Name="dgMain" ItemsSource="{Binding TestArray}" Margin="0,20,0,0" LoadingRow="dgMain_LoadingRow"><DataGrid.Columns><DataGridTextColumn Header="Name" Binding="{Binding Name}"/><DataGridTextColumn Header="Address" Binding="{Binding Address}"/><DataGridTextColumn Header="Age" Binding="{Binding Age}"/></DataGrid.Columns></DataGrid>

I am using the "LoadingRow" event to update the row header:

private void dgMain_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        e.Row.Header = (e.Row.GetIndex() + 1).ToString();
    }

What I want: It sould show the index of the line in the row header.

Whats the problem?: If I add items or load items it works great, but if I sort the DataGird the index of the lines don't change.

unsortedsorted

The left one is unsorted and the right one is sorted (by Name). In this example the index of line "F" should be 6 instead of 1 (right image).

(Not related to the problem: Why are all RowHeaders selected?)

Problem 2:

What I got:see Problem 1

What I want: After I added a row it should jump to the next empty row.

Whats the problem?: If I sort the datagrid it jumps to the next line, even if it is not empty.

monkey

First I sorted the list by name and then I added "A: First", "B: Second", "C: Third" and then "A: Fourth" and because of the sorting "A: Fourth" automatically gets the second line and then it jumps to the third line instead to the last, empty line.

Edit: Sorry, i forgot to say: It should 1. reset the sorting and 2. jump to the last, empty line. The order should be "A: First", "B: S", "C: T" and "A: Fourth".

I really hope there are easy solutions. Thanks :)





Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>