Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I want to update the label control data(text) when I open any file like Excel file.

Please reply.
Posted
Comments
Prasad Khandekar 15-Apr-13 7:21am    
Can you explain your problem in a bit more detail?
Archana Parate 15-Apr-13 7:46am    
I have a imagebutton.

When I click on Imagebutton, it will open a file.
While opening a file, side by side a text will appear on label that on which date the file get opend. It means " File Read on 15-April-2013" text will appear on label control when file is opening.


the code is like below:

Dim fl As New FileInfo("C:\inetpub\ftproot\NewFolder1\External\abc.doc")
If (fl.Exists()) Then
lbl_readon.Text = "File Read on 15-April-2013 "
FileOpen(fl.FullName)
end if
Archana Parate 15-Apr-13 8:04am    
I have a imagebutton.

When I click on Imagebutton, it will open a file.
While opening a file, side by side a text will appear on label that on which date the file get opend. It means " File Read on 15-April-2013" text will appear on label control when file is opening.


the code is like below:

Dim fl As New FileInfo("C:\inetpub\ftproot\NewFolder1\External\abc.doc")
If (fl.Exists()) Then
lbl_readon.Text = "File Read on 15-April-2013 "
FileOpen(fl.FullName)
end if
ZurdoDev 15-Apr-13 7:43am    
OK. Where are you stuck?
Archana Parate 15-Apr-13 8:06am    
The code is like Below :

Dim fl As New FileInfo("C:\inetpub\ftproot\NewFolder1\External\abc.doc")

If (fl.Exists()) Then
lbl_readon.Text = "File Read on 15-April-2013 " FileOpen(fl.FullName)
end if

Actually.

There is no error in the given code.

Actually it opens a file but it does not show the label text while opening a file.

Please tell me how to do it..

1 solution

It doesn't work because you're opening the file on the UI (startup) thread. You're setting the text of the label, but since the thread is busy opening and, possibly, processing the file, the thread cannot get around to processing the WM_PAINT messages your app got to repaint the label with the new text.

Put the code for opening and processing the file in a background thread and it'll work. You can use explicit Threads, a BackgroundWorker component, Tasks from the Task Parallel library, or what have you.

Oh! And don't think you can just move the code for setting the label text to the background thread. It won't work, reliably anyway. You cannot touch UI controls from anything other than the UI thread.
 
Share this answer
 
v2
Comments
Archana Parate 16-Apr-13 2:14am    
can you please show it??
Dave Kreskowiak 16-Apr-13 8:33am    
Nope, cause I don't have the time and it's already been shown thousands of times all over the web.

Read these:

https://www.google.com/#hl=en&gs_rn=9&gs_ri=psy-ab&tok=y8Z-s1JgksV5tJyWuRHl8Q&cp=23&gs_id=2i&xhr=t&q=how+to+use+backgroundworker&es_nrs=true&pf=p&output=search&sclient=psy-ab&oq=how+to+use+background+w&gs_l=&pbx=1&bav=on.2,or.r_qf.&bvm=bv.45175338,d.aWc&fp=8b6e51a45d6e43c7&biw=1920&bih=1105

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900