Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm creating a sharepoint survey with VS2012.

I managed to create the survey with several question and here is some sample:

            SPWeb web = properties.GetWeb();
            Guid id = web.Lists.Add("survey", "desc", SPListTemplateType.Survey);
            SPList list = web.Lists[id];

            string Question1 = "choose from option";
            StringCollection collection1 = new StringCollection();
            collection1.Add("opt 1");
            collection1.Add("opt 2");
            collection1.Add("opt 3");
            list.Fields.Add(Question1, SPFieldType.Choice, true, false, collection1);

My question how can I add a question with type Rating Scale ?

I can't find any sample of doing this, maybe need to use (SPFieldRatingScale) but can't understand how.

Hope for any help or directions TIA

share|improve this question
add comment

2 Answers 2

I managed to do it like that:

string Question3 = "from scale 1 - 5."; StringCollection collection3 = new StringCollection();

            list.Fields.Add(Question3, SPFieldType.GridChoice, true, false, collection3);
            SPFieldRatingScale srs = list.Fields[Question3] as SPFieldRatingScale;
            srs.Choices.Add("some text");
            srs.Choices.Add("another text");
            srs.GridTextRangeLow = "low";
            srs.GridTextRangeHigh = "high";
            srs.GridTextRangeAverage = "avg";
            srs.GridStartNumber = 1;
            srs.GridEndNumber = 5;
            srs.GridNAOptionText = "Not relevant";
            srs.Update();

and than add it to the survey list

share|improve this answer
add comment

I never do that but in the MSDN there is a guide How to: Create a Custom Field Value Class that could help you: http://msdn.microsoft.com/en-gb/library/ms480788.aspx

share|improve this answer
    
I managed to do it like that: –  Ronen Apr 9 '13 at 10:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.