开发者

C# - Moving list box items to new list boxes

开发者 https://www.devze.com 2023-03-19 18:45 出处:网络
I have 3 list boxes. I am splitting a text file to sort the data using regular expressions into the proper listboxes.

I have 3 list boxes. I am splitting a text file to sort the data using regular expressions into the proper listboxes.

At the end of the sort, the user is displayed the 3 list boxes with all of the items in each. However, I want the user to be able to select one (or multiple) lines in a left, middle, or right list box. Once an item(s) is selected the user may click on a button to "move left" or "move right". depending on which box the user is focused on (left, middle, right) will determine where the selected item will move to.

So if the users wants to move an item(s) from the left list to the right 开发者_JS百科list he/she would select the item(s) in the far left list and click the "move right" button. Now the item will be removed from the left list and added to the middle list. Now the user must select it from the middle list and click the "move right" button again to remove it from the middle list and add it to the right list.

If there is any way to move the item all of the way from the left list be clicking twice on the "move right" button that would be even better.


Does anyone know how to go about this in a somewhat simple matter?


The easiest way once you have broken the data into their respective lists is to do something like this (pseudocode)

//from left list
buttonToMiddle()
{
  listMiddle.add(selected text);
  listLeft.remove(selected text);
}

//from middleList
buttonToRight()
{
  listRight.add(selected text);
  listMiddle.remove(selected text);
}

You get the idea, it's really easy and also you may also want to look at any other ways to implement it more efficiently maybe using switch statements and giving the buttons an id or some sort.

This is just a global idea and easy way to do it.


Another option of dubious use is to have a timer activated by the first click. If it expires without registering a second click, in say 0.5 seconds, then it moves the item one column across. If a second click is detected in this time, wait until the timer expires, and move it two columns across. If you have a double click event, I would use it. Otherwise, this method may be helpful.

This method should work for an arbitrary number of columns, but may get hard for users to remember how many times they have clicked.


I assume you have buttons next to the ListBoxes to move selected items to one box or another?

If so, you could add additional buttons to move from left box to right box (skipping the middle), or right to left.

I'm not sure that's the best method from a human factors engineering standpoint, but it's one way to do what I think you're asking.

Edit to Add

I just re-read your post - it looks like you'll want to handle a double-click event (which I'm not sure readily exists). You might want to look into the MouseDown (and MouseUp) events and write your own double-click event.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号