0
How can I get the textbox inside a For:
I have a For that traverses 20 times and I have 20 textbox on my screen, I wonder how I could get all the textbox that contains on name the word "Publishing" pick up the text and play in an array.
0
How can I get the textbox inside a For:
I have a For that traverses 20 times and I have 20 textbox on my screen, I wonder how I could get all the textbox that contains on name the word "Publishing" pick up the text and play in an array.
2
You don’t need to wear one for
for this, you can simply use a Linq query to simplify all this.
Take an example:
var textos = this.Controls.OfType<TextBox>().
Where(control => control.Name.Contains("Publicacao")).
Select(txt => txt.Text).ToArray();
That one query snatch, from the property Controls
form, all controls that are of type TextBox
(or derivatives thereof) whose name contains the literal Publishing and then selects only their text, playing them in the string array (string[]
) textos
.
I liked the solution but it did not work it did not find any textbox.
The TextBoxes
are inside a container on the screen? Something like panel
, groupbox
, etc..
It is, inside a panel
Try replacing this with the panel name. Something like Panel1
1
You can use the property Controls form and run a Line to pick up the controls with the desired name.
List<TextBox> textBoxes = this.Controls.OfType<TextBox>()
.Where(ctrl => ctrl.Name.Contains("Publicacao")).ToList();
Julio, I didn’t bring anything my textbox is called txtPublicacao. txtPublicacao2, txtPublicacao3 List<Textbox> textBoxes = this.Controls.Oftype<Textbox>() . Where(Ctrl => Ctrl.Name.Contains("txtPublication")). Tolist();
If the controls are inside a panel, perform the same code as shown above, but change this to the panel name.
0
You can also use a for going through the controls that are inside the panel. In this function you pass your dashboard, and for will scroll through all Textbox, and those named "Post" will be saved in a list of names, and returned.
Public Function NomesArray(ByRef painel As Control) As List(Of String)
Dim ArrayNomes As New List(Of String)
For Each Control In painel.Controls
If TypeOf Control Is TextBox Then
If DirectCast(Control, txtBusca).Name = "Publicacao" Then
ArrayNomes.Add(DirectCast(Control, txtBusca).Name)
End If
End If
Next
Return ArrayNomes
End Function
Browser other questions tagged c# .net winforms textbox
You are not signed in. Login or sign up in order to post.
Could you tell us more about your question? It has example code?
– rzani
You are using Winforms?
– Jéf Bueno
Jbueno, Yes Winforms
– William