473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

unable to update label that was dinamcly created...

Expand|Select|Wrap|Line Numbers
  1. private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
  2.         {
  3.             Label[] labeli = new Label[2];
  4.             for (int i = 0; i < 2; i++)
  5.             {
  6.  
  7.                 labeli[i] = new Label();
  8.                 labeli[i].Parent = this;
  9.  
  10.  
  11.             }
  12.             labeli[0].Size = new Size(94, 17);
  13.             labeli[0].Location = new Point(145, 114);
  14.             labeli[0].Parent = this;
  15.  
  16.             labeli[1].Size = new Size(94, 17);
  17.             labeli[1].Location = new Point(145, 114);
  18.  
  19.             labeli[0].Text = "clk Freq";
  20.             labeli[1].Text = "inport name";
  21.  
  22.             labeli[0].Hide();
  23.             labeli[1].Hide();
  24.             this.Controls.AddRange(labeli);
  25.  
  26.             if (domainUpDown1.SelectedIndex==0)
  27.             {
  28.                 labeli[0].Show();
  29.                 labeli[0].Visible = true;
  30.                 labeli[0].Update();
  31.                 labeli[0].Refresh();
  32.  
  33.             }
  34.             else if (domainUpDown1.SelectedIndex == 1)
  35.             {
  36.                 labeli[0].Hide();
  37.                 labeli[0].Visible = false;
  38.                 labeli[0].Update();
  39.                 labeli[0].Refresh();
  40.             }
  41.             Application.DoEvents();
  42.             this.Update();
  43.             this.Refresh();
  44.         }
  45.  
*I maked sure, usung brake points, that i am entering the if statments.
*I used labeli[0].Visible = false; / labeli[0].Hide(); Separately - didnt work.
Nov 27 '10 #1
1 1528
GaryTexmo
1,501 Expert 1GB
Can you be more clear on the problem? What exactly is going wrong? I can infer from the code, but it's easier if you just tell us what the problem is... "didn't work" doesn't cut it ;)

Do these labels exist on your form already before this method is run? You're creating new labels in this method every time, so every time the selected item changes on the control that event is tied to, the old labels will still be there and just get overlapped with new ones. If the one before was visible, but the new one is invisible, it will still appear to the old version of the control. You'll also be filling up your form's control list with objects that are no longer useful.

You should make that array a class member and initialize it in the constructor or form load event, adding to the form at that time. Then your selected item changed event can toggle the visibility from there.
Nov 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: codecraig | last post by:
Hi, I am using Tkinter and I have a Label and a Scale. I want to update my label everytime the Scale value changes. What is the best way of doing this? Do i have to bind for every event type? ...
3
by: kaiser | last post by:
Hello, Am new to C# and am playing around trying to get a while loop to display a int on a windows console using label. private void btnGo_Click(object sender, System.EventArgs e) { int Counter...
5
by: David-L. Nadeau | last post by:
Hi ! I have a little problem. I have a process that runs when a user click a button. The process is long to execute (+/- 5 minutes). So, I put a progress bar and now I want to show the evolution...
3
by: Mike Johnson | last post by:
Thanks for the quick responses. I'm having trouble understanding. I've included the code I using. perhaps someone can tell me what I'm doing wrong. My original question was, I'm new to VB.Net...
7
by: Hexman | last post by:
In my program I have several labels that I want to update with information that is being processed in a calculation module. I have code similar to the following in my module. As it goes through...
4
by: Ryan | last post by:
I've got a little bit of code that runs when you enter data in a datasheet view (which is a subform of the form you are in) if rst!DateReceived >= 30 Then Forms!DisposalRecords.Label90.Caption =...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
0
by: RaviEruvuru | last post by:
XSDObjectgen is having the capability of creating the classes with the XSD having another XSD imported in it. when I populate the objects of the class and trying to deserialize the object it is not...
3
by: premMS143 | last post by:
Hello Everybody, A package which is created under VB & Access as a backend is installed in one system.The users are using it without any problem. But now I modified & updated my original VB...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.