views:

457

answers:

0

Hello StackOverflow;

I have a solution running on version 3.5 of the Compact .NET framework, which has many forms on it and datagrids on those forms, utilised to display data from a Sql CE database.

I use an implementation of IBindingList as the source of each of these datagrids, so that I can monitor the state of the underlying data and fire off updates/events etc when it's changed.

When a "click" on a cell is performed, I highlight and select the row that has been clicked, as the form has various events that fire, passing in the strongly typed object that is bound to each row in the grid.

I also have setup, using the HitTest class, events to capture clicks on the column headings to sort the grid ascending/descending. Herein lies the problem - the datagrid only seems to want to be able to select or identify cells by index, e.g. MyGrid.Select(1) selects the 2nd row in the grid.... So when I click the column headings, the grid gets sorted and wherever the selected index was prior to the click, is where it will be after the click - this is not what I want, I want the previously selected item to remain highlighted, regardless of background sorting. I know the Id of the type that is being shown, but I have no way to select that row, based on knowledge of it's Id (data Id, rather than row Id)

What I want to be able to do, is somehow select a row, based on an integer Id property that exists for each strongly-typed object that underpins the value of each row.

E.g.

public class SimpleThing { int Id; string something; string somethingElse; }

MyIBindingListImplementation() myThings = GetMeMyThings(); MyGrid.DataSource = myThings;

MyGrid.Select(0); // Yes, but...I want to select by data, not by index. MyGrid.Select(MyGrid.SelectedItem().Id); // Wishful thinking!

Bare in mind that I'm using the Compact framework and not the full framework and also that I can't use (Or I don't think I can use) DataView, DataRowView and other such-like types, as they revolve around the use of DataTables/DataSets.

Help/Pointers/Abuse appreciated.

-sb

related questions