首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

winform 中listbox绑定了DataSource数据怎么调整选中项的位置

2013-12-21 
winform 中listbox绑定了DataSource数据如何调整选中项的位置? 我想讲成绩调到第一的位置winform 中listbo

winform 中listbox绑定了DataSource数据如何调整选中项的位置?
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.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++;




        }
    }

热点排行