Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I'm writing a program in C# to run sound cues in live theatre. I currently have the program working to load music files into the program and play, but I'm not sure how to display it.

I'm hoping to set it up like a normal music player. I need columns for cue#, title, length, etc. Then I also need to be able to specify which track to play based on what is highlighted. Is there anything on the .NET framework I can do this with?

DataGrid?
That's what I originally looked into, but the only good documentation I could find on it dealt with getting the info out of an SQL database. Do you know any good resources I could check out?
You can point the DataGrid.DataSource at a regular collection that implements IList (eg List<T>). I have more experience with the WPF equivalent, but the fundamentals seem the same.
I've been working on this most of last night and all of today, but I just can't seem to find anywhere that will explain how to do this.

I have a class called SoundCue. Right now, the only relevant thing it's holding is a string of the filename.

In my program, I have List<SoundCue> cue. When a user adds music files to cue, I have the DataGridView.DataSource set equal to cue. When I add multiple files, the DGV will add the correct number of rows. The main problem I'm having now is that I can't figure out how to bind SoundCue's m_filename member variable to a column in my DGV. Am I going about this in the wrong direction?



Code:
        private void addCueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ofdCues.ShowDialog();
            foreach(string file in ofdCues.FileNames)
                cues.Add(new SoundCue(engine, file));
            dgvCues.DataSource = cues;
            dgvCues.Update();
        }




Code:

class SoundCue
    {
        private string m_filename;
        private ISound m_sound;

        public SoundCue()
        {
            m_filename = "";
            m_sound = null;
        }

        public SoundCue(ISoundEngine e, string file)
        {
            m_filename = file;
            m_sound = e.Play2D(m_filename, true, true);
        }

        public void play(ISoundEngine e)
        {
            m_sound.PlayPosition = 0;
            m_sound.Paused = false;
        }

        public void stop()
        {
            m_sound.Paused = true;
        }

        public string getFilename()
        {
            return m_filename;
        }

        public ISound getSound()
        {
            return m_sound;
        }
    }
Don't use fields, use properties; eg

Code:
class SoundCue {
    public string FileName { get; set; }
}
would be a read/write string property called FileName; alternatively use

Code:
class SoundCue {
    public string FileName { get; private set; }
}
for a read-only one.

If you're stuck with C#2 (VS 2005 or lower) and can't upgrade, you'll need to manually implement the properties:

Code:
class SoundCue {
    private string fileName; // backing field for the property
    public string FileName {
        get { return this.fileName; }
        private set { this.fileName = value; }
    }
}


Edit: From the manual getFilename method and casing I guess you're a Java programmer? .NET has real properties, so use those. Smile Guidelines for Names may be an interesting read, too.
Holy cow. Properties make that a heck of a lot easier. You guessed correctly, most of my programming has been in Java and C++. This is my first major C# project.

That's great that my DataGridView automatically makes columns for all of the fields. There are some formatting things I want to play with, but I'm sure I can google for those.

Thank you. Smile
No worries. Smile In addition, here's an article on the PropertyGrid that may come in handy - that too can be pointed at any object and let you edit its properties automatically, and by adding a few [Attributes] to your properties you can tweak it in some rather interesting ways.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement