如果仅编辑txtbox,启用保存按钮吗? [英] Enable the save button if only txtboxes edited?

查看:53
本文介绍了如果仅编辑txtbox,启用保存按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在更新数据库时,我在这里有一些疑问.

1)我有一些文本框(> 3).我有一个保存按钮(将文本框中的数据更新为db)已被禁用.现在,如果编辑了任意一个文本框,我希望启用该按钮.

我的幼稚想法:

为每个文本框创建一个布尔变量,并在文本框状态更改时更改值.但是我想这不是一个好方法.

2)如何使用文本框中的编辑值仅更新db上的特定列,而不更新未更新文本框的db中的其他列.

有没有更好,更专业的人呢?

谢谢,
臭鼬:)
一路学习.....

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.....

推荐答案

处理
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:
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.

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!


看看INotifypropertychanged 界面 [
Have a look at the INotifypropertychanged interface[^].
This can be used to bind data to the data source.


这篇关于如果仅编辑txtbox,启用保存按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆