Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have some doubts here while working with updating the database.

1)I have some textboxes(> 3). I have a save button(update the data in textboxes to db) which was disabled. Now if either 1 of the textbox is edited i want the button to be enabled.

My childish idea:

Create an bool var for each of the textboxes, and change the value if the textbox state changes. But i guess this is not a good way.

2) How we can update only the particular column on db with the edited values from textbox and not update the other columns in db where the textboxes were not updated.

Any better and proffesional way guys?

Thanks,
Skunkhead :)
learning all the way.....
Posted
Updated 2-Feb-11 20:58pm
v3

Handle the TextBox.TextChanged[^] event. Once you have set the textbox content as required in your Form.Load or Form constructor, link in to handle the event for all three TextBoxes:
C#
textBox1.TextChanged += new EventHandler(TextBox_TextChanged);
textBox2.TextChanged += new EventHandler(TextBox_TextChanged);
textBox3.TextChanged += new EventHandler(TextBox_TextChanged);
button1.Enabled = false;

Then, in the handler routine, enable the save button.
C#
void TextBox_TextChanged(object sender, EventArgs e)
    {
    button1.Enabled = true;
    }
You could get clever, and check the current value against the default in the handler, but that's up to you!
 
Share this answer
 
Comments
skunkhead 3-Feb-11 3:16am    
thanks, this is perfect!
Sergey Alexandrovich Kryukov 3-Feb-11 3:18am    
Good enough, a 5. (Well, repeating nearly identical line (and a separate function for a handler) is not elegant at all, but I understand this is only an illustration.) At least, I would do:

foreach(textBox in new textBox[] {textBox1, textBox2, textBox3})
textBox.TextChanged +=
delegate(object sender, WhatEverEventArgs args) {
button1.Enabled = true;
};

--SA
OriginalGriff 3-Feb-11 3:32am    
Anonymous delegates have their place, but I don't want to confuse a beginner by adding completely new concepts when they don't yet know how to handle a basic event. One thing at a time, my friend!
Sergey Alexandrovich Kryukov 4-Feb-11 2:43am    
Makes sense.
I said I understand it's only the illustration. More importantly, you're forced to follow the OP's question, which is anything but reasonable design.
By the way, 2 or 3 very similar question. Like a teacher give the same task to the whole cource, then they rush to computers to ask same thing...
Thank you.
--SA
Have a look at the INotifypropertychanged interface[^].
This can be used to bind data to the data source.
 
Share this answer
 

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