メモリ内のlinqエンティティ結果セットにデータバインドされたリストボックス内のアイテムの再ソートを許可しようとしています。エンティティ レコードは次のように構成されています。
public class DisplayEntity
{
public int IDPK { get; set; }
public int OrderInt { get; set; }
public string Name { get; set; }
}
これらは、フォーム ロード メソッドとファクタ メソッドで整数列によってロードおよびソートされます。
IQueryable<DisplayEntity> entitylist = null;
private void WindowForm_Load(object sender, EventArgs e)
{
entitylist = from e in dbcontext select e;
RefreshList();
}
private void RefreshList()
{
entitylist = entitylist.OrderBy(e => e.OrderInt); //order by
dbcontext.Refresh(RefreshMode.KeepChanges, entitylist);
listBoxEntities.DataSource = entitylist;
}
データセットが初めて読み込まれると正しく並べ替えられますが、その後のデータ変更と RefreshList() 呼び出しではエンティティ リストが並べ替えられません。
private void ChangeOrder(int argIDPK, int argNewPosition)
{
DisplayEntity tempe = (from e in entitylist where e.IDPK == argIDPK select e).First();
tempe.OrderInt = argNewPosition;
RefreshList();
}
ChangeOrder メソッドを使用するのと同様に、メモリ内のエンティティ リスト エンティティの 1 つの名前を変更すると、RefreshList( ) 電話。