Todd MacPherson
asked on
How do I pass lablel.text on one form to textbox.name on another form?
I have a label on one form who's contents are supposed to be the name of a textbox on Form7
How I do I grab the textbox on Form7 so I can pass a subitem value from a listview to it? See my code below for more details and a better explanation:
This code resides on Form21
If clsGlobals.Form7 Is Nothing Then
clsGlobals.Form7 = New Form7
End If
Dim lvi As ListViewItem = lsvList.Items(lsvList.Sele ctedIndice s(0))
clsGlobals.Form7. & lblText.Text = lvi.SubItems(1).Text 'this does not work but I hope you see what I am after. lblText.Text is the name of the textbox on Form7.
clsGlobals.Form7.Show()
clsGlobals.Form7.Focus()
End Sub
How I do I grab the textbox on Form7 so I can pass a subitem value from a listview to it? See my code below for more details and a better explanation:
This code resides on Form21
If clsGlobals.Form7 Is Nothing Then
clsGlobals.Form7 = New Form7
End If
Dim lvi As ListViewItem = lsvList.Items(lsvList.Sele
clsGlobals.Form7. & lblText.Text = lvi.SubItems(1).Text 'this does not work but I hope you see what I am after. lblText.Text is the name of the textbox on Form7.
clsGlobals.Form7.Show()
clsGlobals.Form7.Focus()
End Sub
ASKER
Sorry
I am using Vb.Net 2005
I am using Vb.Net 2005
ASKER
compact framework
Set the Modifiers for the control on the target form to Friend, and reference the control like this:
Dim lvi As ListViewItem = Form7.lsvList.Items(lsvLis t.Selected Indices(0) )
Bob
Dim lvi As ListViewItem = Form7.lsvList.Items(lsvLis
Bob
2005 should make it super easy then...
Something like:
clsGlobals.Form7.Controls( lblText.Te xt) = lvi.SubItems(1).Text
This assumes that the control in question is contained DIRECTLY by the form itself.
If it is in another container, then you would need something like:
clsGlobals.Form7.Panel1.Co ntrols(lbl Text.Text) = lvi.SubItems(1).Text
Or you can "search" for the control using the Form as the root using the new Controls.Find() method.
Something like:
clsGlobals.Form7.Controls(
This assumes that the control in question is contained DIRECTLY by the form itself.
If it is in another container, then you would need something like:
clsGlobals.Form7.Panel1.Co
Or you can "search" for the control using the Form as the root using the new Controls.Find() method.
ASKER
Bob
The listview is on form21. I am trying to pass the selected subitem text value to a textbox on form7.
Form7's textbox name is = Form21's lblText.text
The listview is on form21. I am trying to pass the selected subitem text value to a textbox on form7.
Form7's textbox name is = Form21's lblText.text
See here for an example of Controls.Find():
https://www.experts-exchange.com/questions/22687460/access-a-control-using-a-variable-as-its-name.html
https://www.experts-exchange.com/questions/22687460/access-a-control-using-a-variable-as-its-name.html
If textbox control is placed on the Form (not on some container)
Form7.Controls[lblText.Tex t].Text = lvi.SubItems(1).Text
Goran
Form7.Controls[lblText.Tex
Goran
ASKER
Idle_Mind I tried your solution but it all is blue underlined. The error generated is:
Property 'Item' is 'ReadOnly'
Property 'Item' is 'ReadOnly'
How have you declared "clsGlobals.Form7"
Why do you need this in 2005 anyways? VB.Net 2005 allows you to work with the "default instance" of a form simply by referring to its name:
Form7.Show() ' <--- WITHOUT ever using "New Form7"
You can use "Form7" from ANYWHERE in the project to access this default instance of Form7.
Why do you need this in 2005 anyways? VB.Net 2005 allows you to work with the "default instance" of a form simply by referring to its name:
Form7.Show() ' <--- WITHOUT ever using "New Form7"
You can use "Form7" from ANYWHERE in the project to access this default instance of Form7.
ASKER
This project started out in VB.2003 and then was upscaled to Vb.2005. I do not have the time to go back and change it all.
I declared as follows:
Public Class clsGlobals
#Region "Singleton Forms"
Public Shared Form1 As Form1
Public Shared Form2 As Form2
Public Shared Form3 As Form3
Public Shared Form4 As Form4
Public Shared Form5 As Form5
Public Shared Form6 As Form6
Public Shared Form7 As Form7
Public Shared Form8 As Form8
Public Shared Form9 As Form9
Public Shared Form10 As Form10
Public Shared Form11 As Form11
Public Shared Form12 As Form12
Public Shared Form13 As Form13
Public Shared Form14 As Form14
Public Shared Form15 As Form15
Public Shared Form16 As Form16
Public Shared Form17 As Form17
Public Shared Form18 As Form18
Public Shared Form19 As Form19
Public Shared Form20 As Form20
Public Shared Form21 As Form21
#End Region
End Class
I declared as follows:
Public Class clsGlobals
#Region "Singleton Forms"
Public Shared Form1 As Form1
Public Shared Form2 As Form2
Public Shared Form3 As Form3
Public Shared Form4 As Form4
Public Shared Form5 As Form5
Public Shared Form6 As Form6
Public Shared Form7 As Form7
Public Shared Form8 As Form8
Public Shared Form9 As Form9
Public Shared Form10 As Form10
Public Shared Form11 As Form11
Public Shared Form12 As Form12
Public Shared Form13 As Form13
Public Shared Form14 As Form14
Public Shared Form15 As Form15
Public Shared Form16 As Form16
Public Shared Form17 As Form17
Public Shared Form18 As Form18
Public Shared Form19 As Form19
Public Shared Form20 As Form20
Public Shared Form21 As Form21
#End Region
End Class
Sorry, the mistake was mine.
I forgot to put the ".Text" in there after Controls().
So change this:
clsGlobals.Form7.Controls( lblText.Te xt) = lvi.SubItems(1).Text
To:
clsGlobals.Form7.Controls( lblText.Te xt).Text = lvi.SubItems(1).Text
I forgot to put the ".Text" in there after Controls().
So change this:
clsGlobals.Form7.Controls(
To:
clsGlobals.Form7.Controls(
ASKER
Priest04 your solution generates the following error:
Property access must assign to the property or use its value
Property access must assign to the property or use its value
:) I was wirting it in c#, so I forgot to change brackets from [] to ().
Goran
Goran
Can you not pass By Ref?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Soory to take so long to get back on this. Something came up suddenly and I had to go...anyway I still can not get it to work properly.
This line: clsGlobals.Form7.Controls( lblText.Te xt).Text = lvi.SubItems(1).Text
gives an error: Conversion from string "County" to type 'Integer' is not valid.
Where County was the name of the textbox for this example.
PBLack
This line: clsGlobals.Form7.Controls(
gives an error: Conversion from string "County" to type 'Integer' is not valid.
Where County was the name of the textbox for this example.
PBLack
ASKER
Dim lvi As ListViewItem = lsvList.Items(lsvList.Sele ctedIndice s(0))
Form7.Controls(lblText.Tex t).Text = lvi.SubItems(1).Text
Form7.Show()
Me.Close()
Sorry... here is the code now with the clsGlobals class removed. Same result though
Error: Conversion from string "County" to type 'Integer' is not valid.
I tried it by sending to an established textbox called txtProduct and it worked ( Form7.txtProduct.Text = lvi.SubItems(1).Text ) so I do not know where it is failing.
Form7.Controls(lblText.Tex
Form7.Show()
Me.Close()
Sorry... here is the code now with the clsGlobals class removed. Same result though
Error: Conversion from string "County" to type 'Integer' is not valid.
I tried it by sending to an established textbox called txtProduct and it worked ( Form7.txtProduct.Text = lvi.SubItems(1).Text ) so I do not know where it is failing.
DateTimePciker.Format = Custom, DateTimePciker.CustomForma t = HH:mm
Place this code in form load event
if textBox1.Text = "" then
dateTimePicker1.Value = new DateTime(2007,1,1,0,0,0); // we need to pass any year, month and day
else
dim textBoxDate as DateTime
if DateTime.TryParse(textBox1 .Text, textBoxDate) then
dateTimePicker1.Value = textBoxDate
else
MessageBox.Show("Unrecogni zed time format!")
end if
end if
Just for info, value is not just time, but date + time. It only displays time part of the full date.
Goran
Place this code in form load event
if textBox1.Text = "" then
dateTimePicker1.Value = new DateTime(2007,1,1,0,0,0); // we need to pass any year, month and day
else
dim textBoxDate as DateTime
if DateTime.TryParse(textBox1
dateTimePicker1.Value = textBoxDate
else
MessageBox.Show("Unrecogni
end if
end if
Just for info, value is not just time, but date + time. It only displays time part of the full date.
Goran
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ahhh, I again forgot to translate [] to (). It shoud be
frm.Controls(i).Text = lvi.SubItems(1).Text
Goran
frm.Controls(i).Text = lvi.SubItems(1).Text
Goran
ASKER
Thanks for the help. It is working now.
PBLack
PBLack
Sorry PBLack, I don't know how I missed at the top where you indicated this was for the "compact framework"... =\
I'm guessing VB.Net 2003 since you seem to have your own "global" form collection called "clsGlobals"...but I could be wrong.