1

In a windows forms application, I need a list that shows only one list item at a time but can be scrolled continuously. For example if my list items were:

A B C D

If D was the displayed item and I scrolled down, it would go back to A. This would be similar to a wheel of fortune wheel (although that is not what I am using it for). I figured that the list control would have a continuous scroll option but I have not found such.

I want to mimic this (just the numbers, not the actual lock): enter image description here

Jamie
  • 555
  • 3
  • 14
  • 1
    You might look at using a [`BindingNavigator`](https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/bindingnavigator-control-overview-windows-forms). You would have to manually handle setting the position back to the start when it reaches the end. – Crowcoder Feb 19 '20 at 12:54
  • What do you mean scroll down, if you mean scroll the control that would throw all the users off because that's not how the control should behave. – CodingYoshi Feb 19 '20 at 12:56
  • 3
    Maybe tell us why you want to do that and there may be a better solution available. Make sure this is not an XY problem. – CodingYoshi Feb 19 '20 at 12:58
  • I don't think that there's a simple option to do exactly that. If it means a lot to you, you could probably code the control yourself, though. – laancelot Feb 19 '20 at 12:59
  • It doesn't make sense to ask for a control without describing how it will be used. What is `ABCD`? Images? Texts? Some other controls? – Sinatr Feb 19 '20 at 13:00
  • Are you familiar with the "Linked list" concept? https://en.wikipedia.org/wiki/Linked_list You build an array of objects that have a pointer to the next object, there are several implementations of this that you can check out – Emiliano Javier González Feb 19 '20 at 13:08
  • Use a Form with a next and previous button. Then create a class that steps through the list indexes using the next/previous buttons. – jdweng Feb 19 '20 at 13:23
  • Taking it one step further, we're talking about a [Circular Linked List](https://en.wikipedia.org/wiki/Linked_list#Circular_linked_list) which is something some of us learned about in school. – djv Feb 19 '20 at 16:10
  • This would be used in a method similar to the wheels on a combination lock like the image that I just added to the question. – Jamie Feb 19 '20 at 20:39
  • @Sinatr This will be a list-like control. It will be used to select items from a list just like choosing the number on the padlock shown in the picture. – Jamie Feb 19 '20 at 20:42
  • @Jamie, hello, wondering if the answer below is what you're looking for, if its helped you with your query, would be nice to know or if you need more help – Clint Feb 24 '20 at 20:38
  • @Clint Your answer is sufficient in function. However, I would like something that looks a little more like a wheel or the dials of a combination lock like shown in the image in the question. – Jamie Feb 25 '20 at 02:52

1 Answers1

1

You could use a LinkList<T> to simulate this. I believe you could use the same logic in your winforms such that every event to ScrollSown it can display the next item

Console

var linkList = new LinkedList<int>(new int[] { 1, 2, 3, 4 }.AsEnumerable());

var first = linkList.First;
LinkedListNode<int> current = first;

while (true)
{

   Console.WriteLine($"Current value {current.Value}, press enter to Go Gext");
   Console.ReadLine();
   current = current.Next ?? first;

}

Console Output


WinForms

public LinkedList<object> linkList;
public LinkedListNode<object> current;
public LinkedListNode<object> first;

public Form1()
{
    InitializeComponent();

    linkList = new LinkedList<object>(new object[] { "A", "B", "C", "D" }.AsEnumerable());
    first = linkList.First;
    current = first;
    listBox1.Items.Add(current.Value);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

  current = current.Next ?? first;
  listBox1.Items.Add(current.Value);

}

WinForm Output

Clint
  • 6,011
  • 1
  • 21
  • 28
  • 1
    One could also write an [extension method](https://stackoverflow.com/a/2670199/832052) to `LinkedListNode` to add this functionality. – djv Feb 19 '20 at 16:09