C#数据绑定(DataBinding)简单实现方法
程序员文章站
2023-11-30 11:05:46
本文实例讲述了c#数据绑定(databinding)简单实现方法。分享给大家供大家参考。具体实现方法如下:
using system;
using system...
本文实例讲述了c#数据绑定(databinding)简单实现方法。分享给大家供大家参考。具体实现方法如下:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; namespace appform { public partial class form3 : form { order order = null; public form3() { initializecomponent(); order = new order() { id = 1, customer = "123", orderdate = datetime.now }; initui(); } void initui() { textbox1.databindings.add(new binding("text", order, "id")); textbox2.databindings.add(new binding("text", order, "customer")); textbox3.databindings.add(new binding("text", order, "orderdate")); } void updateui() { textbox1.databindings[0].readvalue(); textbox2.databindings[0].readvalue(); textbox3.databindings[0].readvalue(); } private void button1_click(object sender, eventargs e) { order.id = 2; order.customer = "456"; order.orderdate = datetime.now; updateui(); } } }
希望本文所述对大家的c#程序设计有所帮助。