Re: ListBox items to textbox
vb.net Code:
For Each item In Me.ListBox1.Items.OfType(Of String)
If item.Contains("Point1:") Then Me.TextBox1.Text = item
Next
Re: ListBox items to textbox
Quote:
Originally Posted by
Arve K.
vb.net Code:
For Each item In Me.ListBox1.Items.OfType(Of String)
If item.Contains("Point1:") Then Me.TextBox1.Text = item
Next
That's not really an appropriate use of the OfType method. It is intended as a filter by type, so you'd call it on a list that can contain items of various types when you only want the items of one type, e.g. if you want only Buttons from the Controls collection of a form. In this case, it is the Cast method that is more appropriate, because it is intended to get every item but as a reference of a particular type. That said, you don't need any method if you use a loop, because you can simply declare the loop control variable as the type you want:
vb.net Code:
For Each item As String In Me.ListBox1.Items
That loop is rather inefficient though, because you're going to loop through every item and update the TextBox multiple times when what you actually want is the last matching value. I'd suggest that there should be no need to touch the ListBox at all. We don't know how the ListBox is being populated with the initial or new data but I'd suggest that you should check the data before it's added to the ListBox and if the data contains "Point 1:" then update the TextBox. What's the point in going back over old data or updating the TextBox if there's no new matching data?
Re: ListBox items to textbox
Thank you Arve K. code is working! :)
jmcilhinney I don't mind what's going with old data, I need only updated info and then do mathematical stuff with this.
I want to make this fully auto. When it's new info going from Lan, it's going to ListBox (where all listened things from sockets are put) then write info to textbox (if updated) and then make a calculation.