I really lost heart in tries how to select row in the FastObjectListView (C#, Windows Forms).
I have object and index of this object in the grid, but i can't make it selected! All i've made - move scroll to this row, but not select it.
Methods:
idx = index of row with my object
obj = my object
gvRaces.Items[idx].Selected = true;
gvRaces.SelectObject(obj , true);
gvRaces.SelectedItem = (OLVListItem)gvRaces.Items.Find(obj.Id.ToString(), true).FirstOrDefault(); -
for last method i have a question. What is a key in method ...Items.Find(key, searchAllSubitems)?
all of this methods change properties in my fastObjectListView, but don't change any items visually.
How to select my row?
You already have the right answer:
gvRaces.SelectObject(obj , true);
This would also work (and is probably more what you want):
gvRaces.SelectedObject = obj;
Rev1.0's point is still valid -- make sure that obj
is actually an object in the control. The control uses Equals()
to decide if two objects are equal.
Also, ensure that olv.HideSelection
is false
. This is a very annoying MS provided property that turns off selection when the ListView
doesn't have focus. It makes it look as if SelectObject()
hasn't worked when it actually has.