How do i get the component using component ID

here is what I've done, which works if the component is dynamic, but these are not.

object is to pass the values of the keys into respective(names mirrored) TextBoxes

Show the procedure you use to create textboxes dynamically in order to see the id you use

these are not dynamic, which is why my blocks dont work

how do I do this with static components?

I'm trying to replace this block with a smaller more efficient one

You can't.

You will need to make a list of all your textboxes (the component block at the bottom of the list for each one), then iterate over that list.

1 Like

For a static set like this, you will need an equivalently long global init of a dictionary mapping the text keys into the component blocks of the text boxes that match those keys.

There's no avoiding that.

See this post for sample code, using a list based lookup table and a dictionary.

I suppose the 1:1 method that I'm already using is as good as it gets.

That depends on how many places you traverse the list in your code.
In my app, I needed to traverse the list several time, clearing the components, loading, and testing their contents. Having the components in a structure allowed me to loop over them.

I have them in a structure.

I iterate over the list as a procedure when called

what i was hoping to do was create a situation where if i added keys to the dictionary, that list would grow and I would not need to go back and map the relationship to the TexBox, that naming them in this way I could simply let the dictionary handle the update of mapping.

With the respective TextBox name held in the Dictionary, you can identify the TextBox by iteration of the Block List.

I haven't seen the structure yet.

If the structure is a simple list of components, you would need a way to tie the components to the keys.

If those components are Text Boxes, consider using their unique .Hint values as text keys,
to save hard coding a table or dictionary typing the components to text keys.

Here is a sample that uses that technique ...

(My sample list is growing so big I will have to cross-index it.)

In that case, it's time to graduate from individually named and labelled text boxes to a schema, and just reuse one text box on the fly.

Sample project:

its 3 vertical arragements of textboxes saved to dictionary then saved to file and back

Run time components can't be saved to text files.
Represent the contents and structure in JSON text, and save that text.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.