We help IT Professionals succeed at work.

Form view question

jfgrayiii
jfgrayiii asked
on
Medium Priority
229 Views
Last Modified: 2011-10-03
If I use a form view component how do I referance that field in vb

example formview1  has a field called "name"  when I try to referance this field in the vb source. it tell me that name is not declared
Comment
Watch Question

Commented:
I'm not sure I understand what you mean by "field"...  Do you mean Property?  If so, make sure it's accessible outside the class

Jake

Author

Commented:
If I have a textbox out of a form view I can type

me.textbox1.text = "blah blah"

If that text box is used in a form view  or data grid

me.textbox1 will say not declared

Commented:
me.parent.textbox1.text = "blah blah"

You have to refer to the parent of your control (the form), and then access it's controls.

Jake

Author

Commented:
how would I referance a field from

sqldatasource1
 in
formview1 ?

Commented:
You can set it when you create the FormView1...

For Instance, you could say (in FormView1):

Private SqlDataSource1 As SqlDataSource

Sub New(ByRef SqlDataSource1 As SqlDataSource)
    Me.SqlDataSource1 = SqlDataSource1
End Sub

Now you can access SqlDataSource1 from your FormView1.

Hope that helps,

Jake

Author

Commented:
If I drop a text box on a form I can double click on that box and write vb code

example.

me.textbox1.text = "0"

If I insert a form view component right click on it, go to edit templete, and add a textbox and double click on it
me.textbox1.text does not work  it says textbox 1 not declared how do I declare a referance to textbox1 in a form view


 

Author

Commented:
I am using visual studio 2005 btw
Commented:
Ok...

What I would do is iterate through all of the controls on the form, and add them into the FormView...

private ctrl As Control()

For Each ctrl As Control In Me.Controls
    If ctrl Is Nothing Then
        ReDim ctrl(0)
    Else
        ReDim Preserve ctrl(ctrl.Length)
    End If
    ctrl(ctrl.Length -1) = ctrl
Next

Now, add the ctrl array to the FormView, and voila, you can access any controls in your form.

Let me know if you need more help.

Jake

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.