c# - c# ObjectListView - 更改 vlue 后不更新排序
问题描述
我正在使用 ObjectListView 来显示字典值,它的工作很完美,但是当我对它进行排序一次时,我的意思是当我按年龄降序排序时,它就像{30, 27, 26, 15, 10}
这是我的对象类的一个例子
public class Item: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
int age = -1;
public Int32 Age
{
get{return age;}
set
{
if (value == age)
return;
this.age = value;
OnPropertyChanged("Age");
}
}
}
这也是我如何将对象列表附加到列表视图
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
try
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
stopWatch.Start();
this.listview1.SetObjects(this.ItemsDictionary.Values);
}
finally
{
stopWatch.Stop();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
我用了
this.listview1.Update();
但我知道这是更新控件的绘画而不是排序。
如果 15 岁的对象被更新(增加或减少)排序不会更新并且它仍然在相同的位置,当排序列的任何值发生更改时,我需要做些什么来使其自动排序更新?
解决方案
我通过对我更新的每个项目使用此代码来解决它
this.listview1.Sort(this.listview1.LastSortColumn);
this.listview1.UpdateObject(OBJ);
也许这对其他人有帮助。
推荐阅读
- micronaut - Micronaut HTTP 过滤器修改响应负载
- delphi - 仅从父信息构建 TreeView
- android - 如何使用 gif 图像和进度条创建 Android 启动画面?
- php - 在 laravel 中更新记录时遇到问题。我如何解决它?
- symfony - Symfony 4.4。ExceptionController 和 PreviewErrorController 弃用
- sql - 在 Linq 中使用 ToList() 时避免使用 NVARCHAR
- python - 删除相似数据
- javascript - 通过JS切换具有相同ID的div
- azure-resource-manager - ARM 的部署:模板资源“sql”的授权失败
- excel - 从PowerPoint文件链接时如何打开excel文件的第二个选项卡