Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
Add controls at RunTime in GridBagLayoutPanel
posted

Hi , 

we have requirement that we need load controls like labels, text boxes,drop down,date time,user control etc  at run-time based on our table record.actually are designing questionnaire fill form.questions/answere we get from tables . so its dynamic . 

we find out  GridBagLayoutPanel  which is pretty fast at adding control. design time its fine. but we need load control at run time actually. 

what problem i facing ? 

I've facing problem when i need add new control in middle of some control. 

let say i have drowpdown control with value yes/no . user click on yes.we need add another new control just below dropdown.

let say dropdown control GridBagConstraint OriginX=0 and OriginY=3 . 

below dropdown there will be already some control with origin x=0 , originy=4 and so on . if i need add control in originx=0 and originY=4. then how other controls GridBagConstraint origin values will be change accordingly?? 

e.g we have 4 columns record in table . 

column1 ,             column2 ,                 column3 ,            column4

lblQ1(x0,y0)       , textbox (x1,y0)    ,     lblQ2 (x2,y0)     , datetimepicker(x3,y0)

lblQ3 (x0,y1)       ,DropDown(x1,y1),    lblQ4   (x2,y1)   , Checkboxes (x3,y1)

blQ5 (x0,y2)       , textbox (x1,y2)  ,      lblQ6 (x2,y2)    , datetimepicker(x3,y2)

lblQ7 (x0,y3)       ,DropDown(x1,y3),    lblQ8(x2,y3)     , Checkboxes(x3,y3) 


so let say when user will click on first dropdown of second row (DropDown(x1,y1)) on selected index change i want to add another user control below it.so that it would look like below now.  need span column also here. 

column1 ,             column2 ,                 column3 ,            column4

lblQ1(x0,y0)       , textbox (x1,y0)    ,     lblQ2 (x2,y0)     , datetimepicker(x3,y0)

lblQ3 (x0,y1)       ,DropDown(x1,y1),    lblQ4   (x2,y1)   , Checkboxes (x3,y1)

|-----------------------------------------------------------------------------------------------------
|   this box is usercontrol or groupbox,with controls                                         | (x0,y2) spanX4 
|____________________________________________________________|

blQ5 (x0,y3)       , textbox (x1,y3)  ,      lblQ6 (x2,y3)    , datetimepicker(x3,y3)

lblQ7 (x0,y4)       ,DropDown(x1,y4),    lblQ8(x2,y4)     , Checkboxes(x3,y4

as u can see next control originX,Y values change,moved to next postion. 

how can i do that job at runtime  now ? can u please help me ? 

i'm attaching a sample in which i am just trying to add button in GridBagLayoutPanel   on button click . then on third button on click event i trying to add conrol below it. but i i dont know how do.

can some body take a look at my sample and help me please ?? 

if GridBagLayoutPanel   is not good to use for my requirement then can u please suggest me any other fast Infragistics controls which fit my requirement?  

frmGridBagLayoutPanel.zip