日期:2014-05-17  浏览次数:20533 次

winform 中listbox绑定了DataSource数据如何调整选中项的位置?
 我想讲成绩调到第一的位置
winform 中listbox绑定了DataTable数据如何调整选中项的位置?
要是不绑定DataSource数据源可以调整,绑定DataSource数据源后无法调整选择项位置!

------解决方案--------------------
上下两按钮触发的 

protected void Button_up_Click(object sender, EventArgs e)
    {
        if (this.ListBox_1.SelectedIndex > 0)
        {

            string newValue = this.ListBox_1.SelectedItem.Value;
            string newText = this.ListBox_1.SelectedItem.Text;
            int newIndex = this.ListBox_1.SelectedIndex;

            this.ListBox_1.SelectedItem.Value = this.ListBox_1.Items[newIndex - 1].Value;
            this.ListBox_1.SelectedItem.Text = this.ListBox_1.Items[newIndex - 1].Text;
            this.ListBox_1.Items[newIndex - 1].Text = newText;
            this.ListBox_1.Items[newIndex - 1].Value = newValue;
            this.ListBox_1.SelectedIndex--;

                

        
        }
    }
    protected void Button_down_Click(object sender, EventArgs e)
    {
        if (this.ListBox_1.SelectedIndex < this.ListBox_1.Items.Count - 1)
        {

            string newValue = this.ListBox_1.SelectedItem.Value;
            string newText = this.ListBox_1.SelectedItem.Text;
            int newIndex = this.ListBox_1.SelectedIndex;

            this.ListBox_1.SelectedItem.Value = this.ListBox_1.Items[newIndex + 1].Value;
            this.ListBo