Gustav Brock
Gustav at cactus.dk
Tue Sep 29 08:45:00 CDT 2009
Hi John So you and Shamil have joined a club recapturing your knowledge at beginner's level? Interesting. As for the code, in my scenario it worked because the textbox never had focus when browsing records; focus was at a button or a toolbar or previously moved off the textbox by some other code. On the other hand, if the user types into to textbox it will have focus. This: TextBox textBox = (TextBox)sender; does nothing more than casting the sender object to a variable of type TextBox without using the name of the textbox control making it easier to copy and paste the code to other textboxes. For other types of controls you will need to adjust the code, say: CheckBox checkBox = (CheckBox)sender; What confuses us it, that "changed" here is different from Access. Here it happens whenever the data (text) displayed in the textbox changes - manually or when browsing records. In Access it only happens when the user types into the textbox. /gustav >>> jwcolby at colbyconsulting.com 29-09-2009 15:14 >>> Gustav, > Are we allowed to help with homework? LOL. The homework does not involve classes, collections, or even the messagebox (all used in my version of the homework) because we don't even get to that until next semester. I am just trying to entertain myself and learn something beyond "how does the string object work". This is a first semester C# programming class. We use Murach's C# 2008, and we are currently on chapter 4 - How to work with numeric and string data. That is a cool method of discovering the source of the change event. I have too admit though that I don't fully understand it. It seems that you are casting the sender to a textbox type? Why don't we error if this is not a text box type? And whatever caused the change has the focus, so why doesn't the object (once cast) always say that it has the focus? I'm confused. John W. Colby www.ColbyConsulting.com Gustav Brock wrote: > Hi John > > Are we allowed to help with homework? Some forums explicitly prohibits this! The idea behind homework - ask your teacher - is quite often that you are supposed to work out a solution by yourself as a challenge for your - eh - limited resources! > > Anyway, I had the same issue and worked out this very simple method: > > <code> > private void textBoxName_TextChanged(object sender, EventArgs e) > { > TextBox textBox = (TextBox)sender; > if (textBox.Focused) > { > Console.WriteLine(textbox.Text); > } > } > </code> > > /gustav > > >>>> jwcolby at colbyconsulting.com 29-09-2009 04:26 >>> > No. I am doing a homework assignment where I collect grades in classes, and then move back and > forth through the classes. I have chosen to use a shared text box where the grade classes display > their grades, and the user enters new grades. > > John W. Colby > www.ColbyConsulting.com > > > Michael Maddison wrote: >> Hi John, >> >> Is the control bound? >> >> Cheers >> >> Michael M >> >> -----Original Message----- >> From: dba-vb-bounces at databaseadvisors.com >> [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby >> Sent: Tuesday, 29 September 2009 12:05 PM >> To: VBA >> Subject: [dba-VB] c# text box changed event >> >> I am setting the text in a text box via code which is causing the TextChanged event to fire. I want >> the event to fire for a manual edit so I can set a dirty flag, but not for changing the data by >> code. Is there a change event that fires for manual editing but not by code editing?