0

Is there any class which provide basic selection mechanism? for example:

Imagine I have WAVE file and simple WAV-Editor written in C#. Now I can display this wave file in graphical representation as wave form. In main menu I can click Edit -> Select All, which will select all my samples.

 MySelector ms = new MySelector (0, numOfSamples-1);
 ms.SelectAll;

Ofcourse Ishould can select range block:

ms.Select (from, to);

Or even invert:

ms.InvertSelection ();

Multi select:

ms.AppendSelection (from ,to);

Get information about selected samples:

for (int i=0; i< ms.Size; i++)
if (ms.SelectedAt (i)) DoSomeLogic ();

So, is that class already written or should I do it tommorow :O ?

Thx.

apocalypse
  • 5,764
  • 9
  • 47
  • 95
  • Separate your logic from your UI. There is no "Select" class or "ISelected" interface, because UI elements that can be selected will handle their own selection. You can then retreive `ListBox.SelectedItems()` and work on this list. – CodeCaster Jul 16 '12 at 15:09

3 Answers3

1

I've not been able to find any "official" (built into the framework) classes which vaguely match what you describe, but I've found this article which should help you on your way - I can't see an equivalent to your InvertSelection() method but apart from that it looks promising.

Edit: Upon further searching, I've found that Jon Skeet has a chapter on creating your generic range class in his book C# in depth - see an extract of it on his site here.

Bridge
  • 29,818
  • 9
  • 60
  • 82
1

I don't know of anything in the framework that does only this. It seems like something that would be highly dependent on how you want to keep track of the selections (Selected property, Range of indexes).

Shane Fulmer
  • 7,510
  • 6
  • 35
  • 43
1

How much of this class do you have written already? As it is, I see that you describe

  1. a set of two numbers (longs, perhaps?) to define a time range or sample selection.
  2. The ability to select all times/ samples as a convenience.
  3. a collection of time ranges .
  4. the ability to "hit test" a given time/sample for selectedness.

If you have an API/ POCO for your wave data, you might implement a generic or visitor pattern on it to get the functionality you need. I'm not sure I know of a general purpose "sample range" item within the .net framework.

As an example, though, you might take a look at the code sample at Building a Generic Range class to see if you can make some use of it. I'm not totally sure I agree with some of his operator overloading, but it may be a place for you to start.

Reacher Gilt
  • 1,813
  • 12
  • 26