the documentation refers to rows and columns, however there are no API's to allow the manipulation of this. It in now way documented the same as UltraGridBagLayoutPanel even though the fist part of the documentation says it works exactly like the ...Manager.
Anyway I am trying to design a survey form. The contents of the form is not known at design time, I need to be able to place a series of questions and responses (radio, checkbox, and text) at run-time and have the form look reasonable and be scrollable to get through all of the questions.
Hi Lee,
There is no public Columns or Rows collection in the GridBagLayoutManager. The way GridBagLayouts work is that the rows and columns are logical rows and columns and they are calculated based on the GridBagLayout settings for each object in the layout. I'm not entirely sure if a GridBagLayout would actually help you here for what you are trying to do. It's basically just another way of arranging controls in a container and there is a bit of a learning curve, so you might be better off just positioning your controls using the Anchor or Dock properties in DotNet.
If you have a screen shot or a mock of how one or two of your survey questions might look, I could probably whip up some quick sample code to show you how to achieve that using the GridBagLayout. Presumably you want one survey question per line, so I imagine an UltraPanel that contains all of the questions and handles the scrolling and then each question is an UltraGridBagLayoutManager. Of course, another option you might want to think about is that it's likely your survey questions don't have an infinite variety of possible configuration. So if there are a limited number, maybe a UserControl for each layout might make sense and then you just plug in the different question and answer text.
Well, our Windows Forms suite has a lot of controls. But I guess we don't have one that does that kind of layout in a quick and easy way. You should submit a feature request for a new control:
https://ko.infragistics.com/community/ideas/i/ultimate-ui-for-windows-forms
Its unfortunate that you don't have a more simplistic answer. I went to DevExpresses' Layout control and was able to produce this at first pass.
Any way you slice it, you are going to have to write code that does a lot of math here. I tried to get this to work with GridBagLayoutManager, but the problem is that the panel's AutoSize doesn't know where the bottom is, because the bottom is dependent on the position of the controls, but the GridBagLayoutManager positions the controls based on the panel's size, so it's a catch 22.
What I would do is just handle the Resize event of a panel and arrange everything myself based on the available space. Do you always want two columns? Or do you just want to arrange the questions in a snaking fashion with as many columns as will fit?
I took a shot at doing this in a simple sample. It really has no thing to do with the Infragistcs controls specifically, so it's outside the purview of our support, but I was already knee-deep in trying to get this to work so I went ahead and took a shot at it.GroupBox and UltraGroupBox don't seem to have great support for AutoSize, so you might want to play around with that and maybe even try to calculate the size yourself based on the height of the RadioButtons/Checkboxes. But this code should get you rolling in the right direction.
WindowsFormsApp37.zip
How would I go about calculating spacing? Not something I have had to do before.
Hi,
Okay, so as I was saying, you basically only have 2 different types of questions here. One with CheckBoxes and one with Radio buttons. And the way you have it here, those don't even matter, because the CheckBoxes/RadioButtons are inside a GroupBox, so only the GroupBox itself is contained by the GridBagLayout panel. Frankly, I'm still not sure the GridBagLayout is really appropriate for a layout like this, especially if you want scrolling. In order to get this working correctly with scrolling, I think you would have to calculate the total height needed, because the Panel won't really do that correctly and still keep the spacing. Another down side of a layout like this is that the logical rows span across the entire GridBagLayout panel. So that means that the questions on the same row have to be the same height. There's no way to make this scroll in any kind of snaking way. So the two questions on the first row will be the height of the larger question and the same is tru on every row. So that might waste some vertical space.If it were me, I'd probably just write code to arrange the controls myself within a panel with AutoScroll set to true.