Survey Forms

CodingNewUserCodingNewUser INMember ✭✭
edited June 2018 in General

Hi,
I have created a survey form with different type of questions like radio,checkbox and entry field.
The survey is fine but there is a lot of spacing in between the questions and answers. I need to reduce the space.

public async Task showQuestionsListView(StackLayout ListViewLayout)
{
await getQuestionnaire();
Grid myGrid = new Grid();
myGrid.Padding = 10;
myGrid.RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = GridLength.Auto },
};
myGrid.ColumnDefinitions = new ColumnDefinitionCollection
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
};
int rowCount = 0;
int questioncount = 1;

            Items = new ObservableCollection<CustomRadioButton>();
            ItemsCheckBox = new ObservableCollection<CheckBox>();

            foreach (var item in Settings.VOCQuestionDetailsSettings.RespondantQuestionnare)
            {
                if (item.Mandatory == "Y")
                {
                    StackLayout mandatory = new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal,
                    };

                    mandatory.Children.Add(new Label { Text = "*", TextColor = Color.Red, FontAttributes = FontAttributes.Bold});
                    mandatory.Children.Add(new Label { Text = questioncount + ") " + item.Questions, TextColor = Color.Black, FontAttributes = FontAttributes.Bold});
                    myGrid.Children.Add(mandatory, 0, rowCount);
                }
                else
                {
                    myGrid.Children.Add(new Label { Text = questioncount + ") " + item.Questions, TextColor = Color.Black, HorizontalOptions = LayoutOptions.FillAndExpand, FontAttributes = FontAttributes.Bold }, 0, rowCount);
                }

                rowCount++;
                questioncount++;

                for (int i = 0; i < item.Choices.Count; i++)
                {
                    if (item.QuestionType == "Radio")
                    {
                        CustomRadioButton button = new CustomRadioButton
                        {
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            VerticalOptions = LayoutOptions.FillAndExpand,
                            Text = item.Choices[i],
                            TextColor = Color.Black,
                            FontSize = 14,
                            StyleId = item.Questions,
                            Margin = 1,
                            CheckedChanged = CheckedChanged
                        };
                        Items.Add(button);
                        myGrid.Children.Add(button, 0, rowCount);
                        rowCount++;
                    }
                    else if (item.QuestionType == "TextBox")
                    {
                        var gridentryouter = new Grid();

                        var entrybox = new BoxView();
                        {
                            entrybox.BackgroundColor = Color.Black;
                        };
                        var gridentryinner = new Grid();
                        {
                            gridentryinner.BackgroundColor = Color.White;
                            gridentryinner.Margin = 1;
                        }
                        var editTex = new Renderer.BorderlessEntry();
                        {
                            editTex.FontSize = 14;
                            editTex.HorizontalOptions = LayoutOptions.FillAndExpand;
                            editTex.VerticalOptions = LayoutOptions.FillAndExpand;
                            editTex.HeightRequest = 60;
                            editTex.Completed += textchanged;
                            editTex.StyleId = item.Questions;
                            editTex.TextColor = Color.Black;
                        };

                        gridentryouter.Children.Add(entrybox);
                        gridentryouter.Children.Add(gridentryinner);
                        gridentryinner.Children.Add(editTex);
                        myGrid.Children.Add(gridentryouter, 0, rowCount);
                        rowCount++;
                    }
                    else if (item.QuestionType == "CheckBox")
                    {
                        CheckBox checkbox = new CheckBox();
                        {
                            checkbox.HorizontalOptions = LayoutOptions.FillAndExpand;
                            checkbox.VerticalOptions = LayoutOptions.FillAndExpand;
                            checkbox.DefaultText = item.Choices[i];
                            checkbox.FontSize = 14;
                            checkbox.CheckedChanged += CheckedChangedbox;
                            checkbox.StyleId = item.Questions;
                            checkbox.Margin = 1;
                        }
                        ItemsCheckBox.Add(checkbox);
                        myGrid.Children.Add(checkbox, 0, rowCount);
                        rowCount++;
                    }
                }
            }
            ListViewLayout.Children.Add(myGrid);
    }
Tagged:

Answers

  • M_Shah04M_Shah04 USMember ✭✭✭

    Try to replace myGrid.Padding = 10; with myGrid.Padding = new Thickness(10,10,10,0);
    As right now after question its taking padding of 10 from bottom and for answer its taking padding 10 from top as well, thus its taking 20 padding between question and answer.

  • CodingNewUserCodingNewUser INMember ✭✭

    @M_Shah04 nope that didnt work.No change.

Sign In or Register to comment.