Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Help with Collections

Help with Collections

Scheduled Pinned Locked Moved C#
data-structureshelptutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crushinghellhammer
    wrote on last edited by
    #1

    This might take a few words to explain, so please bear with me if you will: I'm chopping the data of a .WAV file into segments each of length 256 samples. After this segmentation is done, let's say I have N segments. My N by M multidimensional array is called WaveSegments[N,M]. Now, I want to display each of these segments in a UserControl I've made, and want to cycle through the segments by means of an up/down control. So, for example, clicking once on the up control would change the number from 1 to 2, and the display would change from the samples of WaveSegment[1] to WaveSegment[2]. It seems that using collections would ease coding tremendously, but I seem to be running into any number of syntactical problems. Could somebody please demonstrate to me how I could do this? Thank you.

    H 1 Reply Last reply
    0
    • C crushinghellhammer

      This might take a few words to explain, so please bear with me if you will: I'm chopping the data of a .WAV file into segments each of length 256 samples. After this segmentation is done, let's say I have N segments. My N by M multidimensional array is called WaveSegments[N,M]. Now, I want to display each of these segments in a UserControl I've made, and want to cycle through the segments by means of an up/down control. So, for example, clicking once on the up control would change the number from 1 to 2, and the display would change from the samples of WaveSegment[1] to WaveSegment[2]. It seems that using collections would ease coding tremendously, but I seem to be running into any number of syntactical problems. Could somebody please demonstrate to me how I could do this? Thank you.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Actually, using any kind of IEnumerable or IListSource would be great. You can data-bind the collection to the up/down control and use the CurrencyManager.Position property to adjust the position. For more information about data-binding properties and data sources, see Control.BindingContext and CurrencyManager. This would save you from the mess of handling all this yourself. When used correctly, other controls bound to the data source are updated when the position of the current element in the data source is changed. At any rate, what are the "syntactical" problems? For ease, extend CollectionBase and override the methods (or implement new methods with strongly-typed params that call the CollectionBase's methods) and most of the rest of the work is already done (which uses an ArrayList to back the elements).

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      C 1 Reply Last reply
      0
      • H Heath Stewart

        Actually, using any kind of IEnumerable or IListSource would be great. You can data-bind the collection to the up/down control and use the CurrencyManager.Position property to adjust the position. For more information about data-binding properties and data sources, see Control.BindingContext and CurrencyManager. This would save you from the mess of handling all this yourself. When used correctly, other controls bound to the data source are updated when the position of the current element in the data source is changed. At any rate, what are the "syntactical" problems? For ease, extend CollectionBase and override the methods (or implement new methods with strongly-typed params that call the CollectionBase's methods) and most of the rest of the work is already done (which uses an ArrayList to back the elements).

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        C Offline
        C Offline
        crushinghellhammer
        wrote on last edited by
        #3

        Heath, thanks a lot for your post. I'm new to programming, and started with C# as that's the language of choice at my company. Could you give me a code snippet showing how to implement this? Thanks!

        H 1 Reply Last reply
        0
        • C crushinghellhammer

          Heath, thanks a lot for your post. I'm new to programming, and started with C# as that's the language of choice at my company. Could you give me a code snippet showing how to implement this? Thanks!

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          No need - see the documentation for the CollectionBase class in the .NET Framework SDK (just type "CollectionBase" (without quotes) in the Index) and you'll see an example. Be sure to read the documentation - if not skim it over to see what's available in the base class library - especially when starting out.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          C 3 Replies Last reply
          0
          • H Heath Stewart

            No need - see the documentation for the CollectionBase class in the .NET Framework SDK (just type "CollectionBase" (without quotes) in the Index) and you'll see an example. Be sure to read the documentation - if not skim it over to see what's available in the base class library - especially when starting out.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            C Offline
            C Offline
            crushinghellhammer
            wrote on last edited by
            #5

            Thanks Heath, Will get back to you if I run into problems.

            1 Reply Last reply
            0
            • H Heath Stewart

              No need - see the documentation for the CollectionBase class in the .NET Framework SDK (just type "CollectionBase" (without quotes) in the Index) and you'll see an example. Be sure to read the documentation - if not skim it over to see what's available in the base class library - especially when starting out.

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              C Offline
              C Offline
              crushinghellhammer
              wrote on last edited by
              #6

              Heath, I went over the CollectionBase documents, but I guess it's just not very clear to me. I've included some of my code below and it would be great if you could help me out. // Code for class WaveformSegment. public class WaveformSegment { // First we need an object of class "WavFile" to read the contents of the file. // All data is accessed through objWaveToSegment.Data[] public WaveFile objWaveToSegment; // Now we obtain the filename of the file we chose private string m_FileOpened; public string FileOpened { set { m_FileOpened = value; } get { return m_FileOpened; } } // We now formulate a method to extract the information we need public void ChopIntoSegments() { // Obtain access to the data in the .WAV file objWaveToSegment = new WaveFile( m_FileOpened ); objWaveToSegment.Read( ); // Definition of multidimensional array WaveSegments int[,] WaveSegments = new int[17,256]; for(int i = 0; i < 17; i++) { for(int j = 0; j < 256; j++) { WaveSegments[i,j] = objWaveToSegment.Data[(i*64) + j]; } } } // End of ChopIntoSegments()

              H 1 Reply Last reply
              0
              • H Heath Stewart

                No need - see the documentation for the CollectionBase class in the .NET Framework SDK (just type "CollectionBase" (without quotes) in the Index) and you'll see an example. Be sure to read the documentation - if not skim it over to see what's available in the base class library - especially when starting out.

                -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                C Offline
                C Offline
                crushinghellhammer
                wrote on last edited by
                #7

                Heath, I went over the CollectionBase documents, but I guess it's just not very clear to me. I've included some of my code below and it would be great if you could help me out. ************************************************** // Code for class WaveformSegment. public class WaveformSegment { // First we need an object of class "WavFile" to // read the contents of the file. // All data is accessed through // objWaveToSegment.Data[] public WaveFile objWaveToSegment; // Now we obtain the filename of the file we chose private string m_FileOpened; public string FileOpened { set { m_FileOpened = value; } get { return m_FileOpened; } } // This function performs the segmentation public void ChopIntoSegments() { // Obtain access to the data in the .WAV file objWaveToSegment = new WaveFile( m_FileOpened ); // Read() is a function in another file, that reads the data in a .WAV file objWaveToSegment.Read( ); // Definition of multidimensional array // WaveSegments int[,] WaveSegments = new int[17,256]; for(int i = 0; i < 17; i++) { for(int j = 0; j < 256; j++) { WaveSegments[i,j] = objWaveToSegment.Data[(i*64) + j]; } } // End of ChopIntoSegments() ************************************************** Now, I want to write a class SegmentCollection. Here is what I've written so far ************************************************** public class SegmentCollection : System.Collections.CollectionBase { public SegmentCollection() {} public void Add( WaveformSegment WaveSegments ) { this.List.Add( WaveSegments ); } public int IndexOf( WaveformSegment WaveSegments ) { return this.List.IndexOf( WaveSegments ); } public virtual WaveformSegment this [int Index] { get { return (WaveformSegment)this.List[Index]; } } ************************************************** Is this right so far, and how do I access each individual segment? Thank you.

                1 Reply Last reply
                0
                • C crushinghellhammer

                  Heath, I went over the CollectionBase documents, but I guess it's just not very clear to me. I've included some of my code below and it would be great if you could help me out. // Code for class WaveformSegment. public class WaveformSegment { // First we need an object of class "WavFile" to read the contents of the file. // All data is accessed through objWaveToSegment.Data[] public WaveFile objWaveToSegment; // Now we obtain the filename of the file we chose private string m_FileOpened; public string FileOpened { set { m_FileOpened = value; } get { return m_FileOpened; } } // We now formulate a method to extract the information we need public void ChopIntoSegments() { // Obtain access to the data in the .WAV file objWaveToSegment = new WaveFile( m_FileOpened ); objWaveToSegment.Read( ); // Definition of multidimensional array WaveSegments int[,] WaveSegments = new int[17,256]; for(int i = 0; i < 17; i++) { for(int j = 0; j < 256; j++) { WaveSegments[i,j] = objWaveToSegment.Data[(i*64) + j]; } } } // End of ChopIntoSegments()

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  You're not overriding the functionality of the CollectionBase like you're supposed to. See the class documentation itself for an example at the bottom of the page.

                  -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups