Convert
-
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
-
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
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.
-
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
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?)
-
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
Try this:
pattern.WhichWeek = (ReportWS.WeekNumberEnum)System.Enum.Parse(typeof(ReportWS.WeekNumberEnum), Combobox1.SelectedItem.Value);