|
-
May 19th, 2018, 07:03 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
How can I get the text from a Textbox and only this Textbox inside a Panel control in a visual studio Form. Panel is Panel1 and Textbox is txtbox. Thank you.
-
May 19th, 2018, 08:31 PM
#2
Re: Get the Text of a specific Textbox (not all) inside a Panel control
Is the TextBox created at design-time or run-time?
-
May 19th, 2018, 08:34 PM
#3
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
-
May 19th, 2018, 08:45 PM
#4
Re: Get the Text of a specific Textbox (not all) inside a Panel control
Then why is this even a question? When you add controls to a form at design-time, a field is declared that refers to that control. The fact that your TextBox is on a Panel is irrelevant. You refer to this TextBox in exactly the same way as you would if you added it directly to the form. It only matters which control is the parent if you are trying to access the control via its parent's Controls collection, which would generally only be done if you were creating controls at run-time.
-
May 19th, 2018, 08:50 PM
#5
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
txtbox is inside Panel1, so is a child of Panle1. I am no expert in this topic. I understand that first I have to loop the parent and find the child in this case the txtbox control and than get the text form the textbox. Get it ?
-
May 19th, 2018, 08:59 PM
#6
Re: Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by ebellounisoft
I am no expert in this topic.
No, but I am. Why are you arguing with me instead of doing what I've suggested?
 Originally Posted by ebellounisoft
I understand that first I have to loop the parent and find the child in this case the txtbox control and than get the text form the textbox.
No, you don't understand. As I have already explained, the parent of the control is irrelevant if the control was added at design-time because a dedicated field is declared that refers the control directly. I've told you what to do. Just do it. Unless you have lied when you said that the control was added at design-time, it will work.
-
May 19th, 2018, 09:07 PM
#7
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
Searching I found some examples. Let me show you one ok ?.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim allTextBoxValues As String = ""
Dim c As Control
Dim childc As Control
For Each c In Page.Controls
For Each childc In c.Controls
If TypeOf childc Is TextBox Then
allTextBoxValues &= CType(childc, TextBox).Text & ","
End If
Next
Next
If allTextBoxValues <> "" Then
Label1.Text = allTextBoxValues
End If
End Sub
Is not my case but as you can see it is an example of how to locate controls in the Controls collection. As I mention before , I am no expert to write a similar code for the textbox. Thanks anyways.
-
May 19th, 2018, 09:11 PM
#8
Re: Get the Text of a specific Textbox (not all) inside a Panel control
How many times do I have to say the same thing? Code like that is only necessary if you have added the TextBox(es) at run-time, i.e. in code. If you have added the TextBox to your form in the designer then you do not need to access it via the Controls collection of its parent. Have you actually tried to do as I instructed? If not, why not? If so, what happened when you tried?
-
May 19th, 2018, 09:53 PM
#9
Re: Get the Text of a specific Textbox (not all) inside a Panel control
I see from elsewhere that the situation is exactly as I suggested in the first place. Perhaps, in future, you could at least try the advice provided rather declaring that you're not an expert but you know that it won't work. If it indeed does not work then we need to work out why because it means that those trying to help you are misunderstanding the problem and we're not going to be able to help effectively until we do understand the problem. In this case though, it seems that everyone but you understood it right from the start.
-
May 20th, 2018, 09:28 AM
#10
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
I see from elsewhere that the situation is exactly as I suggested in the first place. Perhaps, in future, you could at least try the advice provided rather declaring that you're not an expert but you know that it won't work. If it indeed does not work then we need to work out why because it means that those trying to help you are misunderstanding the problem and we're not going to be able to help effectively until we do understand the problem. In this case though, it seems that everyone but you understood it right from the start.
I presented a sample code. All I ask is for CODE not a rubuke like a 5 year old child. To busy and important to present a code ?. Lot of words but no code , why is it ?.
-
May 20th, 2018, 09:48 AM
#11
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
In other forums they offer me code examples related with collections and I think I am close to solve my problem and learn and understand. They treat me with more respect and no sarcasm !!!
-
May 20th, 2018, 10:43 AM
#12
Re: Get the Text of a specific Textbox (not all) inside a Panel control
If the textbox is not in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
If the textbox is in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
Try it, and let us know what happens (including details, such as any error messages you get).
-
May 20th, 2018, 10:50 AM
#13
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by si_the_geek
If the textbox is not in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
If the textbox is in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
Try it, and let us know what happens (including details, such as any error messages you get).
Textbox is INSiDE the Panel1. Please read my post # 5 which I repeate here : "txtbox is inside Panel1, so is a child of Panle1. I am no expert in this topic. I understand that first I have to loop the parent and find the child in this case the txtbox control and than get the text form the textbox. Get it ?".
Tried your post # 12 and does not work. In my Form I have a Panel and in it a put the texbox.
-
May 20th, 2018, 11:07 AM
#14
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by si_the_geek
If the textbox is not in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
If the textbox is in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
Try it, and let us know what happens (including details, such as any error messages you get).
It is for gentlemen to accept when one is not right. Your code works perfectly. Excuse me if I am upset I am an older person (67) learning. Thank you so much
-
May 20th, 2018, 11:40 AM
#15
Re: Get the Text of a specific Textbox (not all) inside a Panel control
Responding while upset is a bad thing, as ignoring/insulting those who are going out of their way to give up their own time to do you a favour has a negative impact on you.
I recommend that in future you take the time to calm down and try the advice you have been given, as you will get a solution quicker (my post was a re-wording of post #4, but 14 hours later), and people are more likely to help you in future.
I know that some people can seem harsh, but the answers/advice they give can be good. In terms of jmcilhinney, he is unfortunately harsher than most, but he also gives much better answers/advice than most.
As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).
-
May 20th, 2018, 11:45 AM
#16
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
Done !!!. Thank you so much. Open to have you as my friend.
-
May 20th, 2018, 11:46 AM
#17
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by si_the_geek
Responding while upset is a bad thing, as ignoring/insulting those who are going out of their way to give up their own time to do you a favour has a negative impact on you.
I recommend that in future you take the time to calm down and try the advice you have been given, as you will get a solution quicker (my post was a re-wording of post #4, but 14 hours later), and people are more likely to help you in future.
I know that some people can seem harsh, but the answers/advice they give can be good. In terms of jmcilhinney, he is unfortunately harsher than most, but he also gives much better answers/advice than most.
As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).
Done !!!. Thank you so much. Hope to have you as my friend
-
May 20th, 2018, 12:08 PM
#18
Thread Starter
Addicted Member
Re: Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by si_the_geek
If the textbox is not in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
If the textbox is in a panel, you can get the text like this:
Code:
Dim theText as String
theText = txtbox.Text
MessageBox.Show(theText)
Try it, and let us know what happens (including details, such as any error messages you get).
Excuse me. Both codes are the same ?. In Panel and not in Panel ?. Thank you.
-
May 20th, 2018, 12:25 PM
#19
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
Correct... which is what post #4 said (including: "The fact that your TextBox is on a Panel is irrelevant. You refer to this TextBox in exactly the same way as you would if you added it directly to the form.")
-
May 20th, 2018, 07:11 PM
#20
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by ebellounisoft
I presented a sample code. All I ask is for CODE not a rubuke like a 5 year old child. To busy and important to present a code ?. Lot of words but no code , why is it ?.
The problem is not that you were not given code but that you didn't listen to people when they told you what the actual solution was. You had decided what a solution should look like and weren't prepared to accept anything that didn't look like that. You're asking question because you lack knowledge and we are providing answers because we have it. You should consider the answers provided in future, rather than assuming that you already know which answers will be wrong.
 Originally Posted by ebellounisoft
In other forums they offer me code examples related with collections and I think I am close to solve my problem and learn and understand. They treat me with more respect and no sarcasm !!!
At at least one of those other sites, two people did provide you with code and you kept refusing to use it, insisting that it would not work. If you ask a question and multiple people tell you the same thing, you ought to at least consider that it might be correct.
You didn't need another code example though, because you'd already seen all you needed to see. You posted an example of accessing a control yourself:
 Originally Posted by ebellounisoft
Searching I found some examples. Let me show you one ok ?.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim allTextBoxValues As String = ""
Dim c As Control
Dim childc As Control
For Each c In Page.Controls
For Each childc In c.Controls
If TypeOf childc Is TextBox Then
allTextBoxValues &= CType(childc, TextBox).Text & ","
End If
Next
Next
If allTextBoxValues <> "" Then
Label1.Text = allTextBoxValues
End If
End Sub
Is not my case but as you can see it is an example of how to locate controls in the Controls collection. As I mention before , I am no expert to write a similar code for the textbox. Thanks anyways.
I'd already told you that that's how you needed to access your TextBox in this case:
 Originally Posted by jmcilhinney
When you add controls to a form at design-time, a field is declared that refers to that control. The fact that your TextBox is on a Panel is irrelevant. You refer to this TextBox in exactly the same way as you would if you added it directly to the form.
You clearly ignored that though, given that you ask the very question it was answering later:
 Originally Posted by ebellounisoft
Both codes are the same ?. In Panel and not in Panel ?.
The moral of the story is, in my opinion, that if you ask a question and someone provides an answer, give the answer due consideration, even if it's not what you expect. Don't tell people that something doesn't unless you've actually tried it and found that it doesn't work. In this case, you dragged this question on for another day and a half after you had the correct answer.
Now, this may fall on deaf ears but I'll say it anyway. I am criticising you here, but criticism is allowed. It doesn't mean that you are a bad person or that I think that you're a bad person. It just means that I think you did the wrong thing here and I'm explaining what I think you should have done differently. In this case, following that advice would have saved you a day and a half. That's beneficial to you, is it not? That's the point. If you take this criticism on board then you will benefit. If you want to ignore the advice because you don't like being criticised then you're hurting yourself. The choice is yours.
-
May 21st, 2018, 09:43 PM
#21
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
You might find it interesting to look at the .designer.vb file associated with the form. You don't want to be messing with the contents of that file, but it might show you a bit about how the controls work. That form is created by the designer. There's nothing really special about it, except that the designer feels free to re-write it whenever it wants to, so if you do anything in that form...it could go away at any time. That's why you don't want to be changing it. However, it is just code. Up until 2005, the code found in that file was found in a Region block in the .vb file for the form. It was moved to the .designer.vb file only when partial classes were added in 2005.
You can see the .designer.vb file in the Solution Explorer by clicking Show All Files.
The thing to look at in the file is the declaration of all the controls. They are declared in there just like any other variable. You mentioned that the textbox was a child of the panel, but you'd have to study that .designer.vb file to even SEE that the textbox was a child of ANYTHING. It IS in there somewhere, it just won't be so easy to find. What is easy to find is the big, bold, declaration of the textbox as just another variable, so it is as accessible to the rest of the code in the form as any variable you declared at form scope. The fact that it is a child of something is the part that barely matters.
My usual boring signature: Nothing
 
-
May 21st, 2018, 10:01 PM
#22
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by Shaggy Hiker
The fact that it is a child of something is the part that barely matters.
Quite so. A control's parent has an effect on things like z-order and Tab-order but, while you CAN access a control via its parent's Controls collection, it's rare that you ever would. If you want a specific control then you CAN index its parent's Controls collection by name but why would you when you can simply use the field declared for the purpose? The code is simpler and you get a reference of the specific type rather than Control. The only times you'd use the Controls collection of a parent is if you wanted to do something to every control with that parent, in which case you'd just loop, or if you wanted to access a control created at run time, in which case you don't have a dedicated field.
-
May 22nd, 2018, 09:54 AM
#23
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
The problem is not that you were not given code but that you didn't listen to people when they told you what the actual solution was. You had decided what a solution should look like and weren't prepared to accept anything that didn't look like that. You're asking question because you lack knowledge and we are providing answers because we have it. You should consider the answers provided in future, rather than assuming that you already know which answers will be wrong.
At at least one of those other sites, two people did provide you with code and you kept refusing to use it, insisting that it would not work. If you ask a question and multiple people tell you the same thing, you ought to at least consider that it might be correct.
You didn't need another code example though, because you'd already seen all you needed to see. You posted an example of accessing a control yourself:
I'd already told you that that's how you needed to access your TextBox in this case:
You clearly ignored that though, given that you ask the very question it was answering later:
The moral of the story is, in my opinion, that if you ask a question and someone provides an answer, give the answer due consideration, even if it's not what you expect. Don't tell people that something doesn't unless you've actually tried it and found that it doesn't work. In this case, you dragged this question on for another day and a half after you had the correct answer.
Now, this may fall on deaf ears but I'll say it anyway. I am criticising you here, but criticism is allowed. It doesn't mean that you are a bad person or that I think that you're a bad person. It just means that I think you did the wrong thing here and I'm explaining what I think you should have done differently. In this case, following that advice would have saved you a day and a half. That's beneficial to you, is it not? That's the point. If you take this criticism on board then you will benefit. If you want to ignore the advice because you don't like being criticised then you're hurting yourself. The choice is yours.
The best and most professional response was the one of si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 09:55 AM
#24
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
Quite so. A control's parent has an effect on things like z-order and Tab-order but, while you CAN access a control via its parent's Controls collection, it's rare that you ever would. If you want a specific control then you CAN index its parent's Controls collection by name but why would you when you can simply use the field declared for the purpose? The code is simpler and you get a reference of the specific type rather than Control. The only times you'd use the Controls collection of a parent is if you wanted to do something to every control with that parent, in which case you'd just loop, or if you wanted to access a control created at run time, in which case you don't have a dedicated field.
The best and most professional response was the one of si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 09:56 AM
#25
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
Quite so. A control's parent has an effect on things like z-order and Tab-order but, while you CAN access a control via its parent's Controls collection, it's rare that you ever would. If you want a specific control then you CAN index its parent's Controls collection by name but why would you when you can simply use the field declared for the purpose? The code is simpler and you get a reference of the specific type rather than Control. The only times you'd use the Controls collection of a parent is if you wanted to do something to every control with that parent, in which case you'd just loop, or if you wanted to access a control created at run time, in which case you don't have a dedicated field.
The best and most professional response was the one of si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 09:57 AM
#26
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
The problem is not that you were not given code but that you didn't listen to people when they told you what the actual solution was. You had decided what a solution should look like and weren't prepared to accept anything that didn't look like that. You're asking question because you lack knowledge and we are providing answers because we have it. You should consider the answers provided in future, rather than assuming that you already know which answers will be wrong.
At at least one of those other sites, two people did provide you with code and you kept refusing to use it, insisting that it would not work. If you ask a question and multiple people tell you the same thing, you ought to at least consider that it might be correct.
You didn't need another code example though, because you'd already seen all you needed to see. You posted an example of accessing a control yourself:
I'd already told you that that's how you needed to access your TextBox in this case:
You clearly ignored that though, given that you ask the very question it was answering later:
The moral of the story is, in my opinion, that if you ask a question and someone provides an answer, give the answer due consideration, even if it's not what you expect. Don't tell people that something doesn't unless you've actually tried it and found that it doesn't work. In this case, you dragged this question on for another day and a half after you had the correct answer.
Now, this may fall on deaf ears but I'll say it anyway. I am criticising you here, but criticism is allowed. It doesn't mean that you are a bad person or that I think that you're a bad person. It just means that I think you did the wrong thing here and I'm explaining what I think you should have done differently. In this case, following that advice would have saved you a day and a half. That's beneficial to you, is it not? That's the point. If you take this criticism on board then you will benefit. If you want to ignore the advice because you don't like being criticised then you're hurting yourself. The choice is yours.
The best and most professional response was the one of si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 10:00 AM
#27
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
The problem is not that you were not given code but that you didn't listen to people when they told you what the actual solution was. You had decided what a solution should look like and weren't prepared to accept anything that didn't look like that. You're asking question because you lack knowledge and we are providing answers because we have it. You should consider the answers provided in future, rather than assuming that you already know which answers will be wrong.
At at least one of those other sites, two people did provide you with code and you kept refusing to use it, insisting that it would not work. If you ask a question and multiple people tell you the same thing, you ought to at least consider that it might be correct.
You didn't need another code example though, because you'd already seen all you needed to see. You posted an example of accessing a control yourself:
I'd already told you that that's how you needed to access your TextBox in this case:
You clearly ignored that though, given that you ask the very question it was answering later:
The moral of the story is, in my opinion, that if you ask a question and someone provides an answer, give the answer due consideration, even if it's not what you expect. Don't tell people that something doesn't unless you've actually tried it and found that it doesn't work. In this case, you dragged this question on for another day and a half after you had the correct answer.
Now, this may fall on deaf ears but I'll say it anyway. I am criticising you here, but criticism is allowed. It doesn't mean that you are a bad person or that I think that you're a bad person. It just means that I think you did the wrong thing here and I'm explaining what I think you should have done differently. In this case, following that advice would have saved you a day and a half. That's beneficial to you, is it not? That's the point. If you take this criticism on board then you will benefit. If you want to ignore the advice because you don't like being criticised then you're hurting yourself. The choice is yours.
Best and only real solution was from si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 10:02 AM
#28
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
I already mark it as solved !!!!. Please no more post guys. The best and most professional response was the one of si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 10:03 AM
#29
Thread Starter
Addicted Member
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
 Originally Posted by jmcilhinney
Quite so. A control's parent has an effect on things like z-order and Tab-order but, while you CAN access a control via its parent's Controls collection, it's rare that you ever would. If you want a specific control then you CAN index its parent's Controls collection by name but why would you when you can simply use the field declared for the purpose? The code is simpler and you get a reference of the specific type rather than Control. The only times you'd use the Controls collection of a parent is if you wanted to do something to every control with that parent, in which case you'd just loop, or if you wanted to access a control created at run time, in which case you don't have a dedicated field.
The best and most professional response was the one of si_the_geek. Short, concrete and the only one who really understood my question. Post # 12. He is the best !!!
-
May 22nd, 2018, 10:05 AM
#30
Re: [RESOLVED] Get the Text of a specific Textbox (not all) inside a Panel control
Ok, if you want no more answers, I'll close the thread. We don't normally do that, but in this case, I expect it would be best.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|