[dba-VB] SPAM-LOW: Re: c# text box changed event

jwcolby jwcolby at colbyconsulting.com
Tue Sep 29 08:58:02 CDT 2009


Gustav,

 > So you and Shamil have joined a club recapturing your knowledge at beginner's level? Interesting.

I keep good company I suppose?

I never used c# in the past, only vb.net.  The syntax is different enough that it requires at least 
some study.  I use the class to force myself to put in the hours.  As a professional developer it is 
easy to get sidetracked and not do the study, especially when you have no paying work to keep you in 
the area.  Plus theoretically it provides me another place to ask questions, interface with others 
working in the language etc.

I plan on doing this and the next level class, at which point I will be most of the way through the 
book and hopefully well on my way.

John W. Colby
www.ColbyConsulting.com


Gustav Brock wrote:
> 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?
> 
> 
> 
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
> 
> 



More information about the dba-VB mailing list