Results 1 to 6 of 6

Thread: Write a value to a textbox depending on variable

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    7

    Write a value to a textbox depending on variable

    Hello,

    I have a WPF form and created a stackpanel with 5 textboxes. (TXT1, TXT2, TXT3 ....)
    I want to fill these textboxes with a name out of a Global var named "NamePerson" and the textbox depending of the value of i.

    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    Stackpanel1.Children.Item(i).SetValue(NamePerson)
    End Sub

    Can anyone tell me how i can fix this?

    Thanks in advance,

    Erika

  2. #2
    Banned
    Join Date
    Nov 2011
    Posts
    8,510

    Re: Write a value to a textbox depending on variable

    You have to cast Stackpanel1.Children.Item(i) to TextBox and then you can access it's Text property.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    7

    Re: Write a value to a textbox depending on variable

    Quote Originally Posted by Niya View Post
    You have to cast Stackpanel1.Children.Item(i) to TextBox and then you can access it's Text property.
    And how do i do this? (i'm not experienced in WPF/.net)

  4. #4
    Banned
    Join Date
    Nov 2011
    Posts
    8,510

    Re: Write a value to a textbox depending on variable

    Something like this:-
    Code:
    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
        DirectCast(Stackpanel1.Children(i), TextBox).Text = NamePerson
    End Sub
    

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    7

    Re: Write a value to a textbox depending on variable

    Hello Niya,

    Thank you very much, this is what i needed.
    Now i can go further with my task.
    Have a nice weekend.

    Regards,

    Erika

  6. #6
    Banned
    Join Date
    Nov 2011
    Posts
    8,510

    Re: Write a value to a textbox depending on variable

    Sure thing mate. You have fun now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width