我有列表视图表。每当我尝试从列表视图表中删除项目时,列表的顺序变为随机,但是当我将项目添加到列表中时,列表将被排序。每当删除列表时,我希望其余项目按学生ID排序。到目前为止,我已经尝试过并且没有任何运气。
StudentOrder.xaml
<CollectionViewSource
Source="{Binding StudentRecords}">
<CollectionViewSource.SortDescriptions>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
StudentOrder.xaml.cs
void StudentOrder_Loaded(object sender, RoutedEventArgs e)
{
if (Shows.OrderCurrent == null)
{
Show.OrderPresent = StudentID;
Show.DataOrder = "StudentID";
Show.Order();
}
else
{
if (orderLst != null)
{
Show.Order();
}
}
}
ShowOrders.cs
public override bool Delete()
{
recordRetriever.StudentOrderRetriever.Delete(_record);
Record = null;
Refresh();
return true;
}
private ObservableCollection<ShowOrder> RandomListSort()
{
IEnumerable<ShowOrder> arrangeditems = StudentRecords;
if (Orderreplaced)
{
switch (DataOrder)
{
default:
arrangeditems = StudentRecords.OrderBy(s => s.GetType().GetProperty(DataOrder).GetValue(s, null)).ToList();
break;
}
}
Orderreplaced = false;
return new ObservableCollection<RandomListSort>(arrangeditems);
}
public override void Refresh()
{
Refresh();
StudentRecords = RandomListSort();
}
答案 0 :(得分:0)
您没有为排序说明设置的属性。如果不是你以编程方式进行,那么最好将它设置在XAML中,如下所示。
qry.exec("select * from myTable");
QByteArray *outByteArray;
while (qry.next())
outByteArray = new QByteArray(qry.value("myCol").toByteArray());
QBuffer *mediaStream = new QBuffer(outByteArray);
mediaStream->open(QIODevice::ReadOnly);
QMediaPlayer *player = new QMediaPlayer;
QVideoWidget *videoWidget = new QVideoWidget(this);
videoWidget->setGeometry(32, 136, 400, 300);
player->setVideoOutput(videoWidget);
player->setMedia(QMediaContent(),mediaStream);
player->setVolume(50);
player->play();
有关更多文档,请查看以下链接。
https://msdn.microsoft.com/en-us/library/ms742542(v=vs.110).aspx