Etiket: ListBox

How To Move Selected ListItems to Down in ListBox

Ocak 14th, 2009

Call the metod from OnClick Down Button event;
Code ;

public void MoveDown()
    {
        int startindex = ListBox2.Items.Count - 1;
        for (int i = startindex; i > -1; i--)
        {
            if (ListBox2.Items[i].Selected)
            {
                if (i < startindex && !ListBox2.Items[i + 1].Selected)
                {
                    ListItem bottom = ListBox2.Items[i];
                    ListBox2.Items.Remove(bottom);
                    ListBox2.Items.Insert(i + 1, bottom);
                    ListBox2.Items[i + 1].Selected = true;
                }

            }
        }
    }

Tags: , ,
Posted in .NeT 2008 | No Comments »

How To Move Selected ListItems to Up in ListBox

Ocak 14th, 2009

Call the metod from OnClick Up Button event;
Code ;

public void MoveUp()
    {
        for (int i = 0; i < ListBox2.Items.Count; i++)
        {
            if (ListBox2.Items[i].Selected)
            {
                if (i > 0 && !ListBox2.Items[i - 1].Selected)
                {
                    ListItem bottom = ListBox2.Items[i];
                    ListBox2.Items.Remove(bottom);
                    ListBox2.Items.Insert(i - 1, bottom);
                    ListBox2.Items[i].Value = bottom.Value;
                    ListBox2.Items[i - 1].Selected = true;
                }
            }
        }
    }

Tags: , ,
Posted in .NeT 2008 | No Comments »