首页 > Windows开发 > 详细

wpf listbox 选中项 上移下移

时间:2018-09-21 10:35:20      阅读:308      评论:0      收藏:0      [点我收藏+]
原文:wpf listbox 选中项 上移下移


private void MoveUp_Click(object sender, RoutedEventArgs e)

?? ? ? ?{
?? ? ? ? ? ?DataRowView rowView = this.listScrip.SelectedItem as DataRowView;
?? ? ? ? ? ?if (rowView == null)
?? ? ? ? ? ?{
?? ? ? ? ? ? ? ?return;
?? ? ? ? ? ?}


?? ? ? ? ? ?DataRow selRow = rowView.Row;
?? ? ? ? ? ?int index = dtScrip.Rows.IndexOf(selRow);
?? ? ? ? ? ?if (index == 0)
?? ? ? ? ? ?{
?? ? ? ? ? ? ? ?return;
?? ? ? ? ? ?}


?? ? ? ? ? ?DataRow newRow = dtScrip.NewRow();
?? ? ? ? ? ?newRow.ItemArray = dtScrip.Rows[index].ItemArray; ? ? ? ? ? ??
?? ? ? ? ? ?dtScrip.Rows.Remove(selRow);
?? ? ? ? ? ?dtScrip.Rows.InsertAt(newRow, index - 1);


?? ? ? ? ? ?this.listScrip.SelectedIndex = index - 1;
?? ? ? ?}


?? ? ? ?private void MoveDown_Click(object sender, RoutedEventArgs e)
?? ? ? ?{
?? ? ? ? ? ?DataRowView rowView = this.listScrip.SelectedItem as DataRowView;
?? ? ? ? ? ?if (rowView == null)
?? ? ? ? ? ?{
?? ? ? ? ? ? ? ?return;
?? ? ? ? ? ?}
?? ? ? ? ? ?DataRow selRow = rowView.Row;
?? ? ? ? ? ?int index = dtScrip.Rows.IndexOf(selRow);
?? ? ? ? ? ?if (index == dtScrip.Rows.Count - 1)
?? ? ? ? ? ?{
?? ? ? ? ? ? ? ?return;
?? ? ? ? ? ?}


?? ? ? ? ? ?DataRow newRow = dtScrip.NewRow();
?? ? ? ? ? ?newRow.ItemArray = dtScrip.Rows[index].ItemArray;
?? ? ? ? ? ?dtScrip.Rows.Remove(selRow);
?? ? ? ? ? ?dtScrip.Rows.InsertAt(newRow, index + 1);


?? ? ? ? ? ?this.listScrip.SelectedIndex = index + 1;
?? ? ? ?}

wpf listbox 选中项 上移下移

原文:https://www.cnblogs.com/lonelyxmas/p/9684930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!