472,368 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

Loading and Showing a Form before Adding Items to a Listview

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
3 2471
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Eva | last post by:
Hi, I wanted to know how i can enter values into a specific column of a listview. I have tried the following code but this seems to enter all my values into the first column!!! Can anyone...
20
by: Ash Phillips | last post by:
Hi Everyone, I have this program I wrote in VB6 for family use. It's a DVD Database just for me to keep track of them cause I have so many lol. In VB6, I could add items to the ListView in...
7
by: Progalex | last post by:
Hi everybody! I have a listview and a treeview in a form . With an OpenDialog I let the user select multiple files and then these files are added to the listview with the complete pathname,...
2
by: dotnetnewbie | last post by:
Whilst looping through items in a listview I wish to have the option of inserting a new row (in the middle not necessarily at the end of the listview). thus if lvw is the listview name dim...
3
by: Thomas Beyerlein | last post by:
I am writing code for a list box editor, one of the lists is large was hoping that there is a way to either speed it up by making the server do the IF statements of there is a faster way of...
6
by: Josef Brunner | last post by:
Hi, I have a problem using two ListView controls on one and the same form: Problem: The second ListView is never focused. No matter where I "click" non of the items within the ListView is...
1
by: Rune Jacobsen | last post by:
Hi all, I have an application with one particular form that lists a number of items in a listview. In addition to the listview, there is a panel on top with some simple controls to go back and...
9
by: Dimsion | last post by:
Hi, How do i expose all my forms and it controls to other form in the project? I want to be able to add a form and some control on it, this then be available to all other forms. form1 click...
1
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i am looking for a way to clear and fill a listview and right after a treeview nearly flicker and delay free. The TreeView and Listview contain Images and about 1000 Items. What can someone...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.