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
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  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
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    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
    
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  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
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Write a value to a textbox depending on variable

    Sure thing mate. You have fun now
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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