wpf listbox 选中项 上移下移

来源:互联网 发布:删除数据库中所有表 编辑:程序博客网 时间:2024/05/20 00:39


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;
        }
原创粉丝点击