Link to home
Start Free TrialLog in
Avatar of aanimesh
aanimesh

asked on

Tracking the text in dynamically generated text box (also how to modify such boxes)

Hi,

My objective is to display (say n) number of text messages. when user clicks on a message then i should be able to access the related information to that text.
the text messages and related info is stored in a 2 dimentional array and n (and text message array )will keep on changing in runtime.

My approach: I am creating n number of dynamic text objects and printing the messages in sequential order in those boxes. When n changes, i recreate all the text objects (with text coming from the array.)

i also capture mouse click on a text box. however now i need to know what is the index number of this test message in the array so as to access/display other related info.

NOW THE PROBLEM IS : that all the dynamically generated boxes have the same name (the name i give to the object that i include on the form). I cannot assign some ID (i.e. array index no) to each new box' name as it is read only property and so cannot identify the which array position the text belongs to.

I think that one workaround would be to use rich text; include all related info in the text but do not show it (change font color) and when user clicks on a box then read the text in the box, then seperate and display the related info. this is not the best way but if there is no other way then i will have to use it.

ANOTHER RELATED QUESTION: (or should i post is a new question)?
I want the text box height to adjust according to the content. Right now i am setting the height to a specific number. (while i was typing the question i realized that i might calculate the length of the text and then calculate the height to be set dynamically...will try that tomorrow) Is there a method to do it in VB.

Thanks a lot
Animesh
SOLUTION
Avatar of sudhakar_koundinya
sudhakar_koundinya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Create a text box called txtDynamic with an index 0 on your form and make it invisible.

Use this code to dynamically create more text boxes on the fly.

  For i = 1 to arrayCount
    Load txtDynamic(i)
    txtDynamic(i).visible = True
    ...
  Next i

You can get the index number of hte text box on any event using the Index parameter passed to you. for example, on the click event...


Private Sub txtDynamic_Click(ByVal Index as Integer)
  ' the Index tells you the index of the text box
End Sub

Hope this helps
Avatar of aanimesh

ASKER

Hi Sudhakar,

I tried what you suggested. I can assign unique names to each textbox that appears on the form but here is a problem . In this case I cannot write a "text click code" for each of those blocks. (which i am doing now using  Private Sub Text0_Click(Index As Integer)  

my requirement is  to capture which textbox a user has clicked and also execute some code when he does that (this code needs to know the name of the text box in order to know what is displayed in that test box and present some related info ---which can be done using the technique u showed me but in which block do i write the code that will execute when a text box with such unique names is clicked.

am i making sense?
 let me know if it is possible?

Hi Ashooo.....

i am doing what you told but then i do not want the index of the control, i want the identifier that i will give when i assign the text to a textbox (as the index will keep on changing but the identifier that i give will not). Sudhakar has understood what i am doing.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi ashoo...

let me try that....if that cab be done...then that wouuld be greaaat...
thanks a lot man..
will get back to you soon


animesh
hi ashoo...
thanks a lot boss..it worked....really appreciate it....
but can i give some points to sudhakar too...as he also had given an alternate way of doing what i wanted to do....you decide....

thanks a lot once again....
You can split points between us anyway you like.  I'm glad I was of help.
this is upto you friend, any thing is accepted by me :-)

hi sudhakar,

i could not find an option to split points....
but don't worry i will give you another opportunity very soon :-)


all the best guys....thanks a lot once again,
animesh
Thanks aani, but I think there is an option somewhere to split the points. If you want, you can ask the moderator to split the points for you.

Thanks again.
ok no problem :-)

why don't you ask moderators for help, if possible
thanks annieMod.

by the way guys i have another question regarding the same objective.
i am posting a question seperately ..if you guys can help that would be great , especially now that you understand what i am trying to do...

regards,
animesh