C # WPF controls the item sequence of ListBox

Source: Internet
Author: User

There is also a ListBox button that represents the move up and move down,
The idea is:
Insert a duplicate to the specified position and delete the original one.
Remember, the inserted position will move the back part of it (because it is inserted, so it is inserted in 2, and the original content in 2 will become 3 ......)
The push button is as follows:
View sourceprint?
01.
If (ListBox. selecteditem! = NULL & ListBox. selectedindex! = 0)
02.
{
03.
/// =========================================================== Going up the order (the first pen does not move) ========================================== //
04.
// Add a duplicate item Up In The ListBox
05.
// Duplicate selected
06.
Int CH = ListBox. selectedindex;
07.
ListBox. Items. insert (CH-1, ListBox. items [CH]);
08.
// Delete the old item
09.
ListBox. Items. removeat (CH + 1 );
10.
}
If you can accept the above,
Move down:
View sourceprint?
1.
If (ListBox. selecteditem! = NULL & ListBox. selectedindex! = ListBox. Items. Count-1)
2.
{
3.
/// ===================================================Order down (the last one does not move) ========================================== //
4.
Int CH = ListBox. selectedindex;
5.
ListBox. Items. insert (CH + 2, ListBox. items [CH]);
6.
ListBox. Items. removeat (CH );
7.
}
Why is Unit 2 here? As mentioned above, insertion will move others down. If only the next one is inserted, the original one will be placed behind it. In turn, he wants to move two units.
Congratulations ~
Able to solve this problem within one day ~ (Sprinkling flowers)
In fact, I think there is another way to use binding.
It's just getting started with XAML.TOEFL answer
Although there will be less program code in the hands-on scenarios of XAML,
However, SV is too difficult to understand, so we can use this method now.
By the way, The ListBox of SV is dynamically added to the data, that is, the initially empty ListBox. If binding is used, this method is not guaranteed to be useful ~

C # WPF controls the item sequence of ListBox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.