C#: Advanced Guide to Learn C# Programming Effectively by Smith Benjamin

C#: Advanced Guide to Learn C# Programming Effectively by Smith Benjamin

Author:Smith, Benjamin [Smith, Benjamin]
Language: eng
Format: epub
Published: 2021-01-03T00:00:00+00:00


The four types of buttons each have their own functionality and behavior which can further be implemented in different ways. The “all right” button represented as >> is set to transfer all the elements contained in the left list to the right list whenever it is pressed. On the other hand, the “all left” button << does the exact opposite, that is moves the elements from the right to the left list. If it is required that only the selected elements are to be transferred, then the “right” button > is used to transfer them from left to the right list while the “left” button < does so from right to left.

The ListBox is composed of items or elements which are defined as the nested type i.e., ObjectCollection. The ListBox controls responsible for moving the elements around are handled by the method shown below.

1: private void SourceToTarget(ListBox.ObjectCollection source,

2: ListBox.ObjectCollection target)

3: {

4: target.AddRange(source);

5: source.Clear(); 6: }

7:

8: private void MoveAllLeft()

9: {

10: SourceToTarget(listBoxRight.Items, listBoxLeft.Items);

11: }

12:

13: private void MoveAllRight()

14: {

15: SourceToTarget(listBoxLeft.Items, listBoxRight.Items);

16: }

17:

18: private void SourceToTarget(ListBox.SelectedObjectCollection

19: source, ListBox.ObjectCollection target)

20: {

21: IEnumerator e = source.GetEnumerator();

22: while(e.MoveNext())

23: {

24: target.Add(e.Current);

25: }

26: }

27:

28: private void RemoveSelected(ListBox listBox)

29: {

30: for( int i=listBox.Items.Count - 1; i>=0; i--)

31: if(listBox.GetSelected(i))

32: listBox.Items.RemoveAt(i);

33: }

34:

35: private void MoveLeft()

36: {

37: SourceToTarget(listBoxRight.SelectedItems,

38: listBoxLeft.Items);

39: RemoveSelected(listBoxRight);

40: }

41:

42: private void MoveRight()

43: {

44: SourceToTarget(listBoxLeft.SelectedItems,

45: listBoxRight.Items);

46: RemoveSelected(listBoxLeft);

47: }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.