天天看点

wpf listbox 选中项 上移下移

原文:

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)

            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)

            if (index == dtScrip.Rows.Count - 1)

            newRow.ItemArray = dtScrip.Rows[index].ItemArray;

            dtScrip.Rows.InsertAt(newRow, index + 1);

            this.listScrip.SelectedIndex = index + 1;