Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: IndexOf or IndexOfAsync; How to select an item #18

Open
Marco-CH opened this issue Oct 4, 2016 · 0 comments
Open

Doc: IndexOf or IndexOfAsync; How to select an item #18

Marco-CH opened this issue Oct 4, 2016 · 0 comments

Comments

@Marco-CH
Copy link

Marco-CH commented Oct 4, 2016

.NET Framework 4.6.1
Used with WPF DataGrid

In the source code and at Virtualizing Data with XAML I found following description of the methods IndexOf and IndexOfAsync:
"This returns the index of a specific item. This method is optional – you can just return -1 if you don’t need to use IndexOf. It’s not strictly required if don’t need to be able to seeking to a specific item, but if you are selecting items implementing this method is recommended."

And an example at Virtualizing Data with XAML

public int IndexOf(Author item)
{
    return (from a in _ctx.Authors orderby a.AuthorName where a.AuthorName.CompareTo(item.AuthorName <0 select a).Count();
}

The first problem is that if the AuthorName is not unique in your example, a wrong index is returned. Unless the correct index is returned, the VirtualizingObservableCollection has a problem. Correct?

At Virtualizing Data with XAML you write:
Supports true multi-user read/write without resets (maximizing performance for large-scale concurrency scenarios).
Your example on GitHub is unfortunately read-only. Can you explain how a new element to the collection added and selected? Add to database and call this.VOC.ResetAsync()/this.VOC.Clear() or call this.VOC.Insert(index + 1, newItem, DateTime.Now)? As can be avoided that this element is not double in the list after scrolling?

When I bind the SelectedItem of the DataGrid and reorder the list with a selected item, unfortunately all elements are loaded:
GetItemsAtAsync: 0, 100
GetItemsAtAsync: 100, 100
GetItemsAtAsync: 200, 100
GetItemsAtAsync: 300, 100
GetItemsAtAsync: 400, 100
GetItemsAtAsync: 500, 100
...

Can you please publish an example containing CRUD (Create, Read, Update and Delete) operations? It would be nice if we could see the following operations:

this.SelectedItem = newOrChangedItem; //with implemented -> dataGridOrListBox.ScrollIntoView(dataGridOrListBox.SelectedItem);
this.VOC.Add(newItem);
this.VOC.Insert(index, newItem);
this.VOC.Remove(oldItem);
var item = this.VOC.SingleOrDefault(i => i.ItemID == 120);

If you want you can use my example on OneDrive (VS 2015, .NET Framework 4.6.1, EF 6.1.3).
Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant