By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,126 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,126 IT Pros & Developers. It's quick & easy.

Loading and Showing a Form before Adding Items to a Listview

P: n/a
Hello

Ran into a bit of a problem here and have now exhausted my resources to getting this working

What I am trying to do is load and show a simple vb form with a listbox in it

Dim frm_nc_code As New frm_nc_sen
frm_nc_code.Show(

Well what I want to have happen is it loads the form then shows all of the controls on the form (especially the listview control which should be blank at this time)

After the form is finished loading (or at least fully visible to the user), then I want the code to run where it adds about 500 items into this control. (why? because I would like to tell the user that the control is loading with info while its loading the info

Here is the code I use to add the items to the listview when the form is loading

Private Sub frm_nc_send_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Me.lblStatus.Text = "FMS Buffer Loading...

listViewFiles.BeginUpdate(
listViewFiles.Items.Clear(

Dim objDirectoryInfo = New DirectoryInfo(path_fms_buffer

Tr
Dim item As ListViewIte
For Each directory As DirectoryInfo In objDirectoryInfo.GetDirectorie
item = listViewFiles.Items.Add(directory.Name
item.ImageIndex = iconList(directory.FullName
Nex
For Each file As FileInfo In objDirectoryInfo.GetFiles(
item = listViewFiles.Items.Add(file.Name
item.ImageIndex = iconList(file.FullName
Nex
Catch ex As UnauthorizedAccessExceptio
MessageBox.Show(Me, path_fms_buffer + " is not accessible" + System.Environment.NewLine + System.Environment.NewLine + "Access is denied.", path_fms_buffer, MessageBoxButtons.OK, MessageBoxIcon.Stop
End Tr

listViewFiles.EndUpdate(

Me.lblStatus.Text = "FMS Buffer Ready
End Su

Now everything works perfect, just the only problem is when i run the application. VB will add all the items while the form is loading THEN show the form, which is not how I would like it to operate. I would like the form to load and show with an empty listview box and then initiate a function or something where it begins loading the listview with items

Thanks to anyone who can shed some light on how to do this
Jessee Holmes
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Try using a thread.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

ListViewFiles.View = View.Details

Me.Text = "FMS BUFFER Loading"

Dim trdFiles As New System.Threading.Thread(AddressOf LoadListView)

trdFiles.Start()

End Sub

Public Sub LoadListView()

listViewFiles.BeginUpdate()

listViewFiles.Items.Clear()

Dim path_fms_buffer As String = "C:\"

Dim objDirectoryInfo = New DirectoryInfo(path_fms_buffer)

Try

Dim item As ListViewItem

For Each directory As DirectoryInfo In objDirectoryInfo.GetDirectories

item = listViewFiles.Items.Add(directory.Name)

' item.ImageIndex = iconList(directory.FullName)

Next

For Each file As FileInfo In objDirectoryInfo.GetFiles()

item = listViewFiles.Items.Add(file.Name)

'item.ImageIndex = iconList(file.FullName)

Next

Catch ex As UnauthorizedAccessException

MessageBox.Show(Me, path_fms_buffer + " is not accessible" +
System.Environment.NewLine + System.Environment.NewLine + "Access is
denied.", path_fms_buffer, MessageBoxButtons.OK, MessageBoxIcon.Stop)

End Try

listViewFiles.EndUpdate()

Me.Text = "FMS Buffer Ready"

End Sub

Ken

-----------------------

"Holmes" <jh*****@stremel.com> wrote in message
news:23**********************************@microsof t.com...
Hello,

Ran into a bit of a problem here and have now exhausted my resources to getting this working.
What I am trying to do is load and show a simple vb form with a listbox in it:
Dim frm_nc_code As New frm_nc_send
frm_nc_code.Show()

Well what I want to have happen is it loads the form then shows all of the controls on the form (especially the listview control which should be blank
at this time).
After the form is finished loading (or at least fully visible to the user), then I want the code to run where it adds about 500 items into this
control. (why? because I would like to tell the user that the control is
loading with info while its loading the info)
Here is the code I use to add the items to the listview when the form is loading:
Private Sub frm_nc_send_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.lblStatus.Text = "FMS Buffer Loading..."

listViewFiles.BeginUpdate()
listViewFiles.Items.Clear()

Dim objDirectoryInfo = New DirectoryInfo(path_fms_buffer)

Try
Dim item As ListViewItem
For Each directory As DirectoryInfo In objDirectoryInfo.GetDirectories item = listViewFiles.Items.Add(directory.Name)
item.ImageIndex = iconList(directory.FullName)
Next
For Each file As FileInfo In objDirectoryInfo.GetFiles()
item = listViewFiles.Items.Add(file.Name)
item.ImageIndex = iconList(file.FullName)
Next
Catch ex As UnauthorizedAccessException
MessageBox.Show(Me, path_fms_buffer + " is not accessible" + System.Environment.NewLine + System.Environment.NewLine + "Access is
denied.", path_fms_buffer, MessageBoxButtons.OK, MessageBoxIcon.Stop) End Try

listViewFiles.EndUpdate()

Me.lblStatus.Text = "FMS Buffer Ready"
End Sub

Now everything works perfect, just the only problem is when i run the application. VB will add all the items while the form is loading THEN show
the form, which is not how I would like it to operate. I would like the form
to load and show with an empty listview box and then initiate a function or
something where it begins loading the listview with items.

Thanks to anyone who can shed some light on how to do this,
Jessee Holmes

Nov 20 '05 #2

P: n/a
"Holmes" <jh*****@stremel.com> schrieb
Now everything works perfect, just the only problem is when i run the
application. VB will add all the items while the form is loading THEN
show the form, which is not how I would like it to operate. I would
like the form to load and show with an empty listview box and then
initiate a function or something where it begins loading the listview
with items.


Add this sub to your Form:

public shadows sub show
mybase.show
refresh

'move the code from the load event to /this/ location
end sub
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

P: n/a
AWESOME

It works

Great thank you for the help Armin and Ken. First, I tried Ken's solutions with the threading cause I kind of had an idea that that was what I was going to need to use, I tried it once before but couldn't get it to work

I'm not sure if armins code would have worked or not but thank you for the reply just the same

Everything works beautifully now

Much Appreciated
Jessee Holmes
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.