Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

WPF list box dynamically

$
0
0
guys I have created the following codes to add stack panel and the picture and the TextBlock in side of it programmatically.

The TextBlock which is inside of the stack panel is, getting text from the text box input.

I want to know is it possible to save each TextBlock item to the .Xml or .Txt file programmatically like we do in regular ListBox item.

(according to this codes only I can save the last item, Which i entered to the text box, its is over writing last texbox entry. So I want to save all textbox entries to the file )

can anyone give me a clue please
thank you,

my coding are follows,




Class MainWindow 


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        

        Dim tb1 As New TextBlock()
        Dim tb2 As New TextBlock()
        Dim lV As ListBox = New ListBox()
        Dim lbl As New ListBoxItem()
        Dim im As New Image
        Dim stp As New StackPanel()
        'lbl.Content = TextBox1.Text


        Dim textblock1 As New TextBlock()

        '***************************************************** //setting up the image default path
        im.Source = New BitmapImage(New System.Uri("d:\sun.jpg"))

        '*****************************************************    // define the text box entry



        tb1.Text = TextBox1.Text
        'tb2.Text = TextBox2.Text
        ' tb1.HorizontalAlignment = Windows.HorizontalAlignment.Center

        '*****************************************************  // setting up the image settings ( width/ height & the alignment)





        'im.HorizontalAlignment = Windows.HorizontalAlignment.Left
        im.Height = 40
        im.Width = 40
        im.VerticalAlignment = Windows.VerticalAlignment.Top
        im.Stretch = Stretch.Fill
        'im.Margin = New Thickness(-1, -32, -1, -1)

        '****************************************************** //  setting up the stack panel settings 


        'stp.Orientation = Orientation.Vertical
        stp.HorizontalAlignment = Windows.HorizontalAlignment.Left
        stp.Height = 40
        stp.Width = 40
        'stp.Margin = New Thickness(45, 45, 45, 0)


        '**************************************************** // add new Stack pannel to each entry in new row

        Me.ListBox1.Items.Add(stp)

        ' stp.Children.Add(lbl)

        stp.Children.Add(im)

        stp.Children.Add(tb1)
        ' stp.Children.Add(tb2)

        IO.Directory.CreateDirectory("D:\asiri")
        Dim w As New IO.StreamWriter("D:\asiri\address.text")

        Dim i As Integer

        For i = 0 To stp.Children.Count - 1


            w.WriteLine(tb1)

        Next
        w.Close()
        '***************************************************


    End Sub

    
End Class





Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>