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. Convert

Convert

Scheduled Pinned Locked Moved C#
csharpregexhelptutorial
4 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.
  • A Offline
    A Offline
    Agweet
    wrote on last edited by
    #1

    Hi All, i am busy trying to convert an int to a ReportWS.MonthlyDOWRecurrence, this is what i got MonthlyDOWRecurrence pattern = new MonthlyDOWRecurrence(); pattern.WhichWeekSpecified = true; pattern.WhichWeek = Convert.ToInt16(Combobox1.SelectedItem.Value); but i always get the following error: Cannot implicitly convert type 'int' to 'ReportWS.WeekNumberEnum'. An explicit conversion exists (are you missing a cast?) In VB.Net it works if you say: pattern.WhichWeek = CInt(Combobox1.SelectedItem.Value); can someone please tell me how to correct this?

    living life on the flip side

    M OriginalGriffO P 3 Replies Last reply
    0
    • A Agweet

      Hi All, i am busy trying to convert an int to a ReportWS.MonthlyDOWRecurrence, this is what i got MonthlyDOWRecurrence pattern = new MonthlyDOWRecurrence(); pattern.WhichWeekSpecified = true; pattern.WhichWeek = Convert.ToInt16(Combobox1.SelectedItem.Value); but i always get the following error: Cannot implicitly convert type 'int' to 'ReportWS.WeekNumberEnum'. An explicit conversion exists (are you missing a cast?) In VB.Net it works if you say: pattern.WhichWeek = CInt(Combobox1.SelectedItem.Value); can someone please tell me how to correct this?

      living life on the flip side

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      well i not familiar with the classes you are using but as the error is suggesting 'WhichWeek' is an enum value then you might want to try an enum parse. There should be an enum collection for the 'WhichWeek' type which will have a static Parse function. Something like...

      (WhichWeeks)WhichWeeks.Parse(typeof(WhichWeeks), Combobox1.SelectedItem.Value);

      ...I highly doubt that will work but hopefully you will get the idea of what you need to do

      Life goes very fast. Tomorrow, today is already yesterday.

      1 Reply Last reply
      0
      • A Agweet

        Hi All, i am busy trying to convert an int to a ReportWS.MonthlyDOWRecurrence, this is what i got MonthlyDOWRecurrence pattern = new MonthlyDOWRecurrence(); pattern.WhichWeekSpecified = true; pattern.WhichWeek = Convert.ToInt16(Combobox1.SelectedItem.Value); but i always get the following error: Cannot implicitly convert type 'int' to 'ReportWS.WeekNumberEnum'. An explicit conversion exists (are you missing a cast?) In VB.Net it works if you say: pattern.WhichWeek = CInt(Combobox1.SelectedItem.Value); can someone please tell me how to correct this?

        living life on the flip side

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        The answer is in the error message, just cast it: pattern.WhichWeek = (ReportWS.WeekNumberEnum) ... I assume this is C# (correctly) trying to ensure you are setting the enum to valid values only. (Your combo box can only return valid enum members, right?)

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • A Agweet

          Hi All, i am busy trying to convert an int to a ReportWS.MonthlyDOWRecurrence, this is what i got MonthlyDOWRecurrence pattern = new MonthlyDOWRecurrence(); pattern.WhichWeekSpecified = true; pattern.WhichWeek = Convert.ToInt16(Combobox1.SelectedItem.Value); but i always get the following error: Cannot implicitly convert type 'int' to 'ReportWS.WeekNumberEnum'. An explicit conversion exists (are you missing a cast?) In VB.Net it works if you say: pattern.WhichWeek = CInt(Combobox1.SelectedItem.Value); can someone please tell me how to correct this?

          living life on the flip side

          P Offline
          P Offline
          PauloCastilho
          wrote on last edited by
          #4

          Try this: pattern.WhichWeek = (ReportWS.WeekNumberEnum)System.Enum.Parse(typeof(ReportWS.WeekNumberEnum), Combobox1.SelectedItem.Value);

          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