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
  1. Home
  2. General Programming
  3. C#
  4. Foreach cannot operate on a 'method group'. Did you intend to invoke the 'method group'?

Foreach cannot operate on a 'method group'. Did you intend to invoke the 'method group'?

Scheduled Pinned Locked Moved C#
graphicshelpquestion
10 Posts 4 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.
  • T Offline
    T Offline
    Tichaona J
    wrote on last edited by
    #1

    From the code below, I am getting three different errors. The first has to do with the Listbox UpdateBegin/Endupdate. The next error has to do with the 'Foreach' statement and 'in'. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //The result of the open file dialog is either true or false. Nullableresult = dlg.ShowDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = true; dlg.Filter = "Media files (*.mp3 | *.wav | *.wma | *.avi | *.mp4 | *.mpg | *.wmv)"; //If the result of the open file dialog was true then.... if (result == true) { //Stop the list box from drawing while items are added. lstBxList.UpdateBegin(); <<

    L I A T 4 Replies Last reply
    0
    • T Tichaona J

      From the code below, I am getting three different errors. The first has to do with the Listbox UpdateBegin/Endupdate. The next error has to do with the 'Foreach' statement and 'in'. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //The result of the open file dialog is either true or false. Nullableresult = dlg.ShowDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = true; dlg.Filter = "Media files (*.mp3 | *.wav | *.wma | *.avi | *.mp4 | *.mpg | *.wmv)"; //If the result of the open file dialog was true then.... if (result == true) { //Stop the list box from drawing while items are added. lstBxList.UpdateBegin(); <<

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Tichaona J wrote:

      Any ideas...???

      yes. read the documentation for each of the class members you intend to use. and pay attention to Intellisense when it is available. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • T Tichaona J

        From the code below, I am getting three different errors. The first has to do with the Listbox UpdateBegin/Endupdate. The next error has to do with the 'Foreach' statement and 'in'. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //The result of the open file dialog is either true or false. Nullableresult = dlg.ShowDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = true; dlg.Filter = "Media files (*.mp3 | *.wav | *.wma | *.avi | *.mp4 | *.mpg | *.wmv)"; //If the result of the open file dialog was true then.... if (result == true) { //Stop the list box from drawing while items are added. lstBxList.UpdateBegin(); <<

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        dlg.OpenFiles is a method group dlg.OpenFiles() is a method that returns a bunch of strings

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        L 1 Reply Last reply
        0
        • T Tichaona J

          From the code below, I am getting three different errors. The first has to do with the Listbox UpdateBegin/Endupdate. The next error has to do with the 'Foreach' statement and 'in'. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //The result of the open file dialog is either true or false. Nullableresult = dlg.ShowDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = true; dlg.Filter = "Media files (*.mp3 | *.wav | *.wma | *.avi | *.mp4 | *.mpg | *.wmv)"; //If the result of the open file dialog was true then.... if (result == true) { //Stop the list box from drawing while items are added. lstBxList.UpdateBegin(); <<

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          Perhaps you could wrap your code in a PRE block and paste the exact error messages you are getting and indicate which line they are occurring on? Here's an example of how to use a PRE block:

          <pre lang="C#">List<int> x = new List<int> {1, 2, 3};</pre>

          Here's what that looks like:

          List<int> x = new List<int> {1, 2, 3};

          You can edit your original message to make that change.

          [Forum Guidelines]

          T 1 Reply Last reply
          0
          • I Ian Shlasko

            dlg.OpenFiles is a method group dlg.OpenFiles() is a method that returns a bunch of strings

            Proud to have finally moved to the A-Ark. Which one are you in?
            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Ian Shlasko wrote:

            a bunch of strings

            streams actually, which makes it sound like a rather expensive method. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            I 1 Reply Last reply
            0
            • L Luc Pattyn

              Ian Shlasko wrote:

              a bunch of strings

              streams actually, which makes it sound like a rather expensive method. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              I Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #6

              Ah, I was just deriving from context... So he's got more bugs buried underneath the bugs he's spotted :)

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              L 1 Reply Last reply
              0
              • I Ian Shlasko

                Ah, I was just deriving from context... So he's got more bugs buried underneath the bugs he's spotted :)

                Proud to have finally moved to the A-Ark. Which one are you in?
                Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                don't worry, the compiler will spot them. And we will be informed, no doubt. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                1 Reply Last reply
                0
                • A AspDotNetDev

                  Perhaps you could wrap your code in a PRE block and paste the exact error messages you are getting and indicate which line they are occurring on? Here's an example of how to use a PRE block:

                  <pre lang="C#">List<int> x = new List<int> {1, 2, 3};</pre>

                  Here's what that looks like:

                  List<int> x = new List<int> {1, 2, 3};

                  You can edit your original message to make that change.

                  [Forum Guidelines]

                  T Offline
                  T Offline
                  Tichaona J
                  wrote on last edited by
                  #8

                  Thanks everyone...

                  1 Reply Last reply
                  0
                  • T Tichaona J

                    From the code below, I am getting three different errors. The first has to do with the Listbox UpdateBegin/Endupdate. The next error has to do with the 'Foreach' statement and 'in'. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //The result of the open file dialog is either true or false. Nullableresult = dlg.ShowDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = true; dlg.Filter = "Media files (*.mp3 | *.wav | *.wma | *.avi | *.mp4 | *.mpg | *.wmv)"; //If the result of the open file dialog was true then.... if (result == true) { //Stop the list box from drawing while items are added. lstBxList.UpdateBegin(); <<

                    T Offline
                    T Offline
                    Tichaona J
                    wrote on last edited by
                    #9

                    I finally figured it out, this works as intended: //Open files into the list box private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = IsEnabled; dlg.Filter = "Media files(*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv)|*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv|All files(*.*)|*.*"; //The result of the open file dialog is either true or false (didn't work). Nullable<bool> result = dlg.ShowDialog(); //If the result of the open file dialog was true then.... if (result == true) { string[] files; files = dlg.FileNames; foreach (string file in files) { lstBxList.Items.Add(file); } } }

                    L 1 Reply Last reply
                    0
                    • T Tichaona J

                      I finally figured it out, this works as intended: //Open files into the list box private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); //Set properties for the dialog... dlg.Title = "Select one or more media files"; dlg.Multiselect = IsEnabled; dlg.Filter = "Media files(*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv)|*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv|All files(*.*)|*.*"; //The result of the open file dialog is either true or false (didn't work). Nullable<bool> result = dlg.ShowDialog(); //If the result of the open file dialog was true then.... if (result == true) { string[] files; files = dlg.FileNames; foreach (string file in files) { lstBxList.Items.Add(file); } } }

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      yes, that looks better, except that you are still not using PRE tags to show a code snippet. :((

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                      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