|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
problems using the tablelayoutpanel in VS2005Sorry if I am posting in wrong group...
I am having a problem adding controls dynamically to this control ( using tablelayoutpanel.add(col,row)). I am doing this to a cell where there is an existing control. I thought this would just move the existing control to the next available cell and so on. (Growstyle is rows). The controls are added in a strange way and the order of the added controls seems to be dependent on what kind of control I am adding!? I will be happy for any comment on this matter. Lars Show quote :-)) On 2007-11-22 06:21:42 -0800, lars.molle***@nve.no said:
> Sorry if I am posting in wrong group... There's no TableLayoutPanel.Add() method.> > I am having a problem adding controls dynamically to this control > ( using tablelayoutpanel.add(col,row)). > I am doing this to a cell where there is an existing control. I Perhaps you could be more specific. What does the code you're using to > thought this would just move the existing control to the next > available cell and so on. (Growstyle is rows). The controls are added > in a strange way and the order of the added controls seems to be > dependent on what kind of control I am adding!? add controls look like exactly? What behavior did you expect? What behavior did you get instead? Pete On 22 Nov, 19:12, Peter Duniho <NpOeStPe***@NnOwSlPiAnMk.com> wrote:
Show quote > On 2007-11-22 06:21:42 -0800, lars.molle***@nve.no said: I'll give a brief description of the problem; I am inserting a row of> > > Sorry if I am posting in wrong group... > > > I am having a problem adding controls dynamically to this control > > ( using tablelayoutpanel.add(col,row)). > > There's no TableLayoutPanel.Add() method. > > > I am doing this to a cell where there is an existing control. I > > thought this would just move the existing control to the next > > available cell and so on. (Growstyle is rows). The controls are added > > in a strange way and the order of the added controls seems to be > > dependent on what kind of control I am adding!? > > Perhaps you could be more specific. What does the code you're using to > add controls look like exactly? What behavior did you expect? What > behavior did you get instead? > > Pete controls in the tablelayoutpanel. There is no such thing as a .addrow method to the control so I use. tablelayoutpanel.controls.add(control,colnr,rownr). I add a control into a cell allready inhabited by a control. I think the existing control is suppose to float to the right. Growstyle is set to rows. I have 7 cols thus after doing this 7 times I have inserted a row. But the result is trange. The order of the inserted controls seem allmost arbitrary and dependent of what kind og control I insert (textbox, checkbox etc.). I am sure there must be a bug in the tablelayoutpanel but will be happy for any ideas. Lars Show quote :-)) On 2007-11-26 05:26:34 -0800, Larsemann <lars.molle***@nve.no> said:
> [...] I add a control Well, again you have failed to post the code you're using. It's pretty > into a cell allready inhabited by a control. I think the existing > control is suppose to float to the right. Growstyle is set to rows. I > have 7 cols thus after doing this 7 times I have inserted a row. But > the result is trange. The order of the inserted controls seem allmost > arbitrary and dependent of what kind og control I insert (textbox, > checkbox etc.). I am sure there must be a bug in the tablelayoutpanel > but will be happy for any ideas. much impossible to tell you what is going wrong without knowing what it is you're actually doing. For you to get any useful help, you need to put together and post a concise-but-complete example of code that reliably demonstrate the problem. "Concise" mean you only include the bare minimum required to demonstrate the problem. "Complete" means one doesn't have to add anything at all to get the code to compile and run (yes, for a forms-based application this means including the designer-created code too, unless you write something from scratch without the designer). As for there being a bug in TableLayoutPanel, that's extremely unlikely. I wouldn't go so far as to say there are no bugs in .NET -- any sufficiently complex piece of software will have bugs -- but they are extremely rare relative to the size of the framework, and I've never seen a bug in a part of the framework that's as commonly used as the TableLayoutPanel. It's not unusual for someone to post here that they think they've found a bug in .NET. I can't recall a single instance of such a claim turning out to be correct. It's much more likely that you've made some assumption about the behavior of adding controls to the panel that's incorrect, and thus your expectations don't match the actual behavior. But until you post something more explicit, there's no way to help explain the disparity. Pete On 26 Nov, 19:01, Peter Duniho <NpOeStPe***@NnOwSlPiAnMk.com> wrote:
Show quote > On 2007-11-26 05:26:34 -0800, Larsemann <lars.molle***@nve.no> said: Hello and thanks for reply.> > > [...] I add a control > > into a cell allready inhabited by a control. I think the existing > > control is suppose to float to the right. Growstyle is set to rows. I > > have 7 cols thus after doing this 7 times I have inserted a row. But > > the result is trange. The order of the inserted controls seem allmost > > arbitrary and dependent of what kind og control I insert (textbox, > > checkbox etc.). I am sure there must be a bug in the tablelayoutpanel > > but will be happy for any ideas. > > Well, again you have failed to post the code you're using. It's pretty > much impossible to tell you what is going wrong without knowing what it > is you're actually doing. > > For you to get any useful help, you need to put together and post a > concise-but-complete example of code that reliably demonstrate the > problem. "Concise" mean you only include the bare minimum required to > demonstrate the problem. "Complete" means one doesn't have to add > anything at all to get the code to compile and run (yes, for a > forms-based application this means including the designer-created code > too, unless you write something from scratch without the designer). > > As for there being a bug in TableLayoutPanel, that's extremely > unlikely. I wouldn't go so far as to say there are no bugs in .NET -- > any sufficiently complex piece of software will have bugs -- but they > are extremely rare relative to the size of the framework, and I've > never seen a bug in a part of the framework that's as commonly used as > the TableLayoutPanel. > > It's not unusual for someone to post here that they think they've found > a bug in .NET. I can't recall a single instance of such a claim > turning out to be correct. > > It's much more likely that you've made some assumption about the > behavior of adding controls to the panel that's incorrect, and thus > your expectations don't match the actual behavior. But until you post > something more explicit, there's no way to help explain the disparity. > > Pete I know that claiming a bug seems a bit far out but quite few of my highly experienced collegues have looked into the solution and comes up with the same response. There must be a bug! You state that it is a commonly used control. I am not sure that is correct, at least not adding/manipulating it dynamically. I have searched the net extensively and am not able to find much about the topic. You want me to give you more code. I'll be happy to mail you the entire soulktion if you want to. For now I will give you the method adding the row, plz let me know if there are some obvious mistakes or misunderstandings on my behalf. Lars :-)) public void settinn_linje(Control[] Kontroller){ this.tableLayoutPanel1.Visible = false; int intLinjetrykket = this.tableLayoutPanel1.GetRow(this.ActiveControl); for (int teller = 6; teller > -1 ; teller--) { if (teller == 0 | teller == 1 | teller == 2) { TextBox midBox = new TextBox(); midBox.Text = Kontroller[teller].Text; this.tableLayoutPanel1.Controls.Add(midBox, 0,intLinjetrykket); } if (teller == 3) { TextBox midBox = new TextBox(); midBox.Text = Kontroller[teller].Text; this.tableLayoutPanel1.Controls.Add(midBox, 0,intLinjetrykket); } if (teller == 4 | teller == 5 | teller == 6) { CheckBox midBox = new CheckBox(); midBox = (CheckBox)Kontroller[teller]; this.tableLayoutPanel1.Controls.Add(midBox, 0, intLinjetrykket); } } bool_Ischanged = true; this.tableLayoutPanel1.Visible = true; } On 2007-11-27 02:04:56 -0800, Larsemann <lars.molle***@nve.no> said:
> I know that claiming a bug seems a bit far out but quite few of my So you say. I remain unconvinced.> highly experienced collegues have looked into the solution and comes > up with the same response. There must be a bug! > You state that it is No, I do not want you to. If you want the best answer, you need to > a commonly used control. I am not sure that is correct, at least not > adding/manipulating it dynamically. I have searched the net > extensively and am not able to find much about the topic. You want me > to give you more code. I'll be happy to mail you the entire soulktion > if you want to. post an appropriate sample of code here in this newsgroup. > For now I will give you the method adding the row, plz Even the short example you posted fails both the "concise" and > let me know if there are some obvious mistakes or misunderstandings on > my behalf. "complete" criteria. It's not concise because there's apparently more in the example than is needed to reproduce the problem, and it's not complete because I can't just compile the whole thing without adding other stuff to get it to work. The fact that the code is not complete also means that we have no information on the state of the control prior to calling the method you posted. How many controls have already been added? Where where they added? And why do you create a new CheckBox() control, only to replace it with an existing CheckBox() from your Kontroller array? Do you understand that a control can only be in one cell at a time, so if you are calling Add() with a reference to a control that you've already placed in the TableLayoutPanel somewhere, it will be removed from its existing location and added where you tell it to? I will say one thing about the code you did post: you should be using the "||" operator in your if() statements, and not the "|" operator. Whatever "highly experience colleagues" you showed your code to should have told you the same thing. Since == has higher precedence than |, I would guess this isn't causing a problem here. But it certainly isn't a good way to write the code. And the million dollar question: have you stepped through the code in a debugger to ensure that it is in fact adding the controls you expect it to, when you expect it to? There really is no substitute for watching the code executed, when trying to find out why when it executes it doesn't do what you expect it to. Pete On 27 Nov, 20:35, Peter Duniho <NpOeStPe***@NnOwSlPiAnMk.com> wrote:
Show quote > On 2007-11-27 02:04:56 -0800, Larsemann <lars.molle***@nve.no> said: I will leave it here. Your ironic tone is starting to bug me.> > > I know that claiming a bug seems a bit far out but quite few of my > > highly experienced collegues have looked into the solution and comes > > up with the same response. There must be a bug! > > So you say. I remain unconvinced. > > > You state that it is > > a commonly used control. I am not sure that is correct, at least not > > adding/manipulating it dynamically. I have searched the net > > extensively and am not able to find much about the topic. You want me > > to give you more code. I'll be happy to mail you the entire soulktion > > if you want to. > > No, I do not want you to. If you want the best answer, you need to > post an appropriate sample of code here in this newsgroup. > > > For now I will give you the method adding the row, plz > > let me know if there are some obvious mistakes or misunderstandings on > > my behalf. > > Even the short example you posted fails both the "concise" and > "complete" criteria. It's not concise because there's apparently more > in the example than is needed to reproduce the problem, and it's not > complete because I can't just compile the whole thing without adding > other stuff to get it to work. > > The fact that the code is not complete also means that we have no > information on the state of the control prior to calling the method you > posted. How many controls have already been added? Where where they > added? And why do you create a new CheckBox() control, only to replace > it with an existing CheckBox() from your Kontroller array? Do you > understand that a control can only be in one cell at a time, so if you > are calling Add() with a reference to a control that you've already > placed in the TableLayoutPanel somewhere, it will be removed from its > existing location and added where you tell it to? > > I will say one thing about the code you did post: you should be using > the "||" operator in your if() statements, and not the "|" operator. > Whatever "highly experience colleagues" you showed your code to should > have told you the same thing. Since == has higher precedence than |, I > would guess this isn't causing a problem here. But it certainly isn't > a good way to write the code. > > And the million dollar question: have you stepped through the code in a > debugger to ensure that it is in fact adding the controls you expect it > to, when you expect it to? There really is no substitute for watching > the code executed, when trying to find out why when it executes it > doesn't do what you expect it to. > > Pete |
|||||||||||||||||||||||