0

C# windows form here. And I know this database structure is possibly as bad as the kraken but it's what I have to work with. Table in the database houses Question and field names that are associated with that question. So for example, if the Question was List 5 reasons you came in today. The fieldnames would be something along the lines of reason1, reason2, reason3, reason4, reason5. Just for further example, this may paint the picture better of how this is setup

PollQuestion ----------- FieldName
5 reasons you cam in?    reason1
                         reason2
                         reason3
                         reason4
                         reason5
Fav video you saw?       favorVideo
Three improvements?      improve1
                         improve2
                         improve3

Aite, so I need the fieldNames to line up on one line with there corresponding Poll Questions so it should read like this

PollQusetion1  --- reason1 reason2 reason3 reason4 reason5
PollQuestion2 ---- favorVideo
PollQuestion3 ---- improve1 improve2 improve3

I am polling the database and storing the poll questions & fieldnames in two separate list variables, then outputting to a flowlayout panel. I was trying to use the logic of this to keep the fieldnames on the same lines as pollquestion but it isn't working as needed.

if (pollquestion != "") { flowlayoutpanel1.SetFlowBreak(fieldname, true); }

However, that isn't giving me the desired output. Can someone with more experience on this matter, please assist me? And if further coding is needed, I can produce that as well. Thanks in advance to all who view, and provide insight!

EDIT ---- 111 This is the output the if statement gives me -

PollQusetion1  --- reason1 reason2 reason3 reason4 reason5 PollQuestion2 ---- favorVideo
PollQuestion3 ---- improve1 improve2 improve3

EDIT ------ 2222 This is an image of what I was referencing of how the if() statement works. I need all the textboxes to be on the one line, then starting with the 2nd Label Test Text & texbox to be on it's own line. enter image description here

  • What is not working? `SetFlowBreak` or `if`? I mean, do you struggle with logic or do you need some help with debugging (aka, why `SetFlowBreak` is not working). – Sinatr Nov 05 '14 at 13:31
  • @Sinatr the layout of how I need the pollquestions & fieldnames to display on the flowbreakout panel are not displaying properly. – MasterOfStupidQuestions Nov 05 '14 at 13:37
  • Ok, does `if` works? Do you ever get `SetFlowBreak` called? Perhaps your pollquestion is `null` and you have to use `string.IsNullOrEmpty()`. – Sinatr Nov 05 '14 at 13:39
  • @Sinatr see edit for how the if() statement causes output to be displayed. – MasterOfStupidQuestions Nov 05 '14 at 13:44
  • Set breakpoint on `SetFlowBreak` call, does it ever triggers? From given edit it looks like it's not. So you have problem with `if`. Have you tried `string.IsNullOfEmpty()`? – Sinatr Nov 05 '14 at 13:48
  • Yes the SetFlowBreak is hit and triggers. I tried to modify code to use string.IsNullOrEmpty() and same output as using my if() statement. – MasterOfStupidQuestions Nov 05 '14 at 13:53
  • Ok, then what is `fieldname`? Is `fieldname` control match to `pollquestion`? Is `flowlayoutpanel1` right panel? You have to provide more code where you deal with those. Or simply look yourself for mistakes there (when breakpoint is hit observe values, are they match to what they should be or you have made a mistake somewhere). – Sinatr Nov 05 '14 at 13:58
  • fieldname matches what the fieldname is in the table. Example, reason1, reason2 etc etc. I attached an image of how the if() statement is displaying the output if that helps any. – MasterOfStupidQuestions Nov 05 '14 at 14:02
  • Do you reuse them? Or why flow break is set for first textbox only? Try to do it this way `flowlayoutpanel1.SetFlowBreak(fieldname, !string.IsNullOrEmpty(pollquestion));` without any `if`. – Sinatr Nov 05 '14 at 14:08
  • @Sinatr using flowlayoutpanel11.SetFlowBreak(fieldname, !string.IsNullOrEmpty(pollquestion)); produces the same output as my image/if() statement. – MasterOfStupidQuestions Nov 05 '14 at 14:12
  • Provide more code please or simply check yourself why `reason1` control have flow break set and `label2` is not. [Click](http://msdn.microsoft.com/en-us/library/y740d9d3.aspx) link ;) – Sinatr Nov 05 '14 at 14:18

1 Answers1

0

I think you should maybe try to use a TableLayoutPanel combined with a Panel.

So starting with the table layout you create with two columns and as many rows as questions are there. In the first column you put a label (multiline, Dock = Fill) where you enter your question text. In the second column you put a panel (also fill docked) where you insert all the text boxes (or checkboxes, radio buttons, etc) you like, but with Dock = Top.

The next hard part is to determine the heigth of each row. This can be accomplished by simply counting the number of field names per question and multiply it with some magic number each option occupies (e.g. 20px) plus some little padding (maybe 5px).

Oliver
  • 43,366
  • 8
  • 94
  • 151
  • I can't set the dock = fill as their is data @ top. Can I set it to fill only the bottom or give a x/y coordinate to begin fill? – MasterOfStupidQuestions Nov 05 '14 at 15:14
  • @MasterOfStupidQuestions: Where is data @ top? I only talked about the dock style of all the elements within the table layout. I didn't say anything about the dock style of the table layout itself. – Oliver Nov 06 '14 at 08:08
  • But if you have two controls you can set one (or multiple) to dock top and one to dock fill. Then all your top controls would sit at the top and the filled control would take the space that would be left over. If that doesn't work for you, you have to know that in case of the dock property order matters. So in design view open View - Other windows - Document Outline and ensure that the Fill control is the first and all other are coming below it. Within the document outline you are able to change this ordering. – Oliver Nov 06 '14 at 08:12