[dba-VB] c# text box changed event

jwcolby jwcolby at colbyconsulting.com
Tue Sep 29 08:14:31 CDT 2009


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