List Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a list box that contains 4000 + lines that I have imported using the
fileopen function etc.

Once I have the data in the list box, I want to scroll through the lines in
the list box displaying the contains of each line in a text box that is on
the form. My command button scrolls through the loop but doesn't populate the
information in the text box as requested. I have copied the code below, can
somebody please advise me why the information is not appearing in the text
box.

I know that is is processing the items because if you see the lines of code
remed out .... If i = 100 then.... This displays the information.


Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim i As Integer
Dim ii As Integer
ii = 0
Dim strValue As String
For i = 0 To lstFiles.Items.Count - 1

txtTemp.Text = lstFiles.Items(i)
'If i = 100 Then
'MessageBox.Show("Test", txtTemp.Text)
'End If
Next i

' This all works
'Dim t As String
'If lstFiles.SelectionMode = SelectionMode.One Then
'txtTemp.Text = lstFiles.SelectedItem.ToString()
'End If
't = txtTemp.Text.Substring(0, 5)
'MessageBox.Show("Substring Test", t)
End Sub
 
* "=?Utf-8?B?QmlsbCBQYXJ0cmlkZ2U=?= said:
I know that is is processing the items because if you see the lines of code
remed out .... If i = 100 then.... This displays the information.

Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim i As Integer
Dim ii As Integer
ii = 0
Dim strValue As String
For i = 0 To lstFiles.Items.Count - 1

txtTemp.Text = lstFiles.Items(i)
'If i = 100 Then
'MessageBox.Show("Test", txtTemp.Text)
'End If
Next i

You will only see the text assigned to the textbox in the last iteration.
 
Actually it *does* propulate the textbox with your information
but you can't see it since the internal code that draws it on the screen
is never given a chance to run until you return from this method
(and at that stage it will have the value from the last iteration)

Even if you did invoke the drawing code the text would change so
fast that you wouldn't be able to see it anyway.

What are you trying to accomplish?

/claes
 
Try adding a Application.DoEvents in your loop to see if that gives you the
effect you want to see. Or maybe a Thread.Sleep(0).
====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Back
Top