Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam new to this programming method. the case is I have created the checkbox and textbox dynamically where the name of the text box and check box is equal and it is handled using database.

The data i need to get is from the textbox which is selected using checkbox by the user

The details in the array need to be name of the textbox and its corsponding value textbox

i created the checkbox and textbox using this method.. some thing related to this

VB
Dim checkBox = new CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(offset, 10)
checkBox.Text = cur
checkBox.Checked = True
checkBox.Size = New Size(100, 20)



i successfully created checkbox at run time .help me getting the value.. and also suggest me with the suitable array list .
Posted

I have absolutely no idea what you mean by "suggest me with the suitable array list" - you shouldn't be using ArrayList anyway, there were superseded by the Generic List<T> class many years ago...

But...if you create a dynamic check box (and generally speaking, it's a poor idea, there are normally better ways to handle this kind of thing) all you need to do is keep a reference to it at a class level when you construct it: move the checkBox variable declaration to the class instead of inside the method and it will be persisted for later use.

Alternatives, you could look in the Controls array and find it - but unless you add a distinguishing feature such as a Name property, you won't be able to tell which is which if you create more than one.
 
Share this answer
 
Comments
Santhoshpettacode 23-Nov-14 11:40am    
Thanks for your answer sir. I new to this logical thing where from your answer i can come to some correct solution. well can you guide me with any reference program .example to your answer so that it will be help full for me to write a correct and clear program.
OriginalGriff 23-Nov-14 11:55am    
No - because I have no idea what you are trying to achieve!
I assume this is part of your homework - but I don't know what homework you have been assigned...
Hi ...
When you create your Checkbox you should give it a Name. With this given Name you could find in inside the controls-collection of the from (or the container-control) to ask for it's checked-state.

Another possibility is to add a handler to a named Sub which allows you to react directly on the changing of the state of the Checkbox. But ... when you use this way you must later remove the handler when you dispose the form, you are in.

Greetings
Ralf
 
Share this answer
 
You can user OfType method in VB.NET.

If you have multiple controls of same type or one control, Use following method :

VB
for each CheckBox as CheckBox In <controlcontainer>.Controls.OfType(Of CheckBox)()
     <controlcontainer>.Controls(CheckBox.Name).Text)
next 
</controlcontainer></controlcontainer>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900