Hello all,

I am unsure of how to do this, but I know it's possible. I have in my
form several labels, where I have set the Tag property value of each
to some int key value of a dictionary collection (say
list<SomeObject,int>).

Now I have a function that is called based on changes to the list, but
what I want to be able to do is to work on the Text property of label
that matches they appropriate key using some kind of referencing
technique. Now I know I can just keep using if statements and make the
code to handle this huge, but this would be too unproductive. So for
example I am thinking of the following (I am using delegate as it is
part of an anonymous event):

delegate EventCode (Object source, arguments....)
{
  int key = (int)source;
  String lbl;

  if (key == lbl1.Tag)
  {
    lbl = lbl1.Text;
  }
  else if (key == lbl2.Tag)
  {
    lbl = lbl2.Text;
  }
  // and so on...

  // now work with it by assigning things to it
  lbl = list[key].Text          // this is a property of SomeObject
  // do some operations and refresh
  lbl = list[key].Text
  // and so on
}

Is this correct? Is there a simpler way? Even better, is there a way
to have a property reference another? Say I link lbl1.Text to list
[1].Text and whenever the latter is updated so will the label, is this
possible? Will I need to override some Paint/OnPaint method of the
form for this to work correctly? I am a bit lost and your help is
appreciated. Also please keep in mind that I had just recently picked
up C# (and this is the reason for my question) so please use some
detail when refering to objects/code specific to the language.

Thanks in advance,
Alon

Reply via email to