Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / January 2007

Tip: Looking for answers? Try searching our database.

threads: datagridvew works but not textboxes, etc?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Beemer Biker - 29 Jan 2007 15:58 GMT
New to threading in C#, I discovered I needed a delegation mechanism to
update a textbox (for example) from a timer thread.  However, the timer
thread seems to have no problem getting data from my datagridview nor
"selecting" a row nor updating an unbound value on that grid.  Did I luck
out or will  I eventually get a cross thread error?

I have a datagrid of events:  start times and duration bound to access mdb.
I used the C# timer (not a waitable timer) as described here
http://www.dotnet247.com/247reference/msgs/43/216845.aspx
to handle my scheduling.

I have a timer to start the event (audio collection) and a second one to
signal it to stop.  The one that stops the previous event starts the next
one.   The program cycles thru the datagrid and start over running
continuously.  It all seems to work, but the first time I put in a
groupbox_ScheduleInfo.text = "Next Production: " +
ScheduledStart.ToLongTimeString() + " " + ScheduledStart.Millisecond;

I got an error that quote "the thread that created groupbox_ was not the
same one that was updating it"  (or something to that effect).  OK, I
understand I need to delegate the update to the groupbox caption using
ISynchronizeInvoke.  But how is it that the same thread can increment an
item in the grid and display it and not get an error?
long iNum =
Convert.ToInt32(dataGridView1.Rows[CurrentFrequency].Cells[ID_SigsAcq].Value)
+ 1;
dataGridView1.Rows[CurrentFrequency].Cells[ID_SigsAcq].Value = iNum;

Also, the above two lines are awkward.  I do not know if long is int32 or
int64 and it seems I should be able to do to this all in one line but the
compiler didnt like the ++:  Operator '++' cannot be applied to operand of
type 'object'

Signature

=======================================================================
Joseph "Beemer  Biker" Stateson
http://ResearchRiders.org     Ask about my 99'R1100RT
=======================================================================

Bart Mermuys - 29 Jan 2007 19:33 GMT
Hi,

> New to threading in C#, I discovered I needed a delegation mechanism to
> update a textbox (for example) from a timer thread.  However, the timer
> thread seems to have no problem getting data from my datagridview nor
> "selecting" a row nor updating an unbound value on that grid.  Did I luck
> out or will  I eventually get a cross thread error?

Not sure, but afaik you shouldn't update Controls from another thread then
the one that created them.   You could check Form/Control InvokeRequired
property and if it's true then you need to use Invoke or BeginInvoke, even
if it works without.

HTH,
Greetings

> I have a datagrid of events:  start times and duration bound to access
> mdb. I used the C# timer (not a waitable timer) as described here
[quoted text clipped - 22 lines]
> compiler didnt like the ++:  Operator '++' cannot be applied to operand of
> type 'object'

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.