Home Forums WPF controls Xceed DataGrid for WPF Cancel auto-select first row

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #40600 |

    Good day,

    I am using DataGridControl. When I refreshing ItemsSource it default auto-select first row, but I dont’t want this behavior. So how can I remove it?

    Also I try selected row after refreshing. I used event ItemsSourceChangeCompleted but it doesn’t work.

    private void LoadData()

    {

        this.PeopleList = new List<People>();

        this.PeopleList.Add(new People { Name=”David”, Age=”22″});

        this.PeopleList.Add(new People { Name=”Anna”, Age=”20″}); 

        this.NotifyPropertyChanged(“PeopleList“); 

     

    private void dataGrid_ItemsSourceChangeCompleted(object sender, EventArgs e)

    {

        var item = this.PeopleList.FirstOrDefault(q => q.Name == “Anna”);

        if (item != null)

            this.dataGrid.SelectedItem = item;

        else

            this.dataGrid.SelectedItem = null; 

     

    In first loading event ItemsSourceChangeCompleted doesn’t work. After refreshing it work.

    Imported from legacy forums. Posted by Vyacheslav (had 1012 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear support, can I get answer from you?

    Imported from legacy forums. Posted by Vyacheslav (had 319 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Vyacheslav,

    I am not sure I correctly understand your requirement.

    For example: you have a list of items in your DataGrid. One of the rows is selected (not the first one, but one a few ‘pages’ down). You then refresh the ItemsSource and the DataGrid automatically sets the position back to the first row.

    This behavior is normal. The data is completely removed and replaced, and the DataGrid has no way of knowing which record represents the same one it was on before the refresh, or if it’s even still there (it could have been removed or modified, or this could be completely different data).

    What behavior are you trying to obtain instead?

    Imported from legacy forums. Posted by Diane [Xceed] (had 298 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Diane,

    Thanks for your answer. But I don’t want that DataGrid selected row after refresh at all. I want to choose selected row myself.

     Sorry for bad english)) 

    Imported from legacy forums. Posted by Vyacheslav (had 758 views)

    Salaktus
    Participant
    Post count: 6

    I’m facing the same problem.

    Vyacheslav did you find a solution for that?

    Thank you

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.