导致集合中的两个绑定绑定到同一个属性
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;
namespace SchoolMate.Windows
{
public partial class UserInfo : Form
{
public UserInfo()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlConnection cn = null;
Link.SQLConnection sqlcn = new SchoolMate.Link.SQLConnection();
SqlDataAdapter da1;
BindingSource myBindingSource;
private void UserInfo_Load(object sender, EventArgs e)
{
cn = sqlcn.SQlconnection();
cn.Open();
da1 = new SqlDataAdapter("SELECT * FROM webapp.UserInfo", cn);
da1.Fill(ds, "UserInfo");
myBindingSource = new BindingSource();
myBindingSource.DataSource = ds.Tables["UserInfo"];
this.textBox1.DataBindings.Add("Text", myBindingSource, "Name");
this.textBox2.DataBindings.Add("Text", myBindingSource, "Sex");
this.dateTimePicker1.DataBindings.Add("Value", myBindingSource, "RegDate");
this.textBox3.DataBindings.Add("Text", myBindingSource, "QQ");
this.textBox4.DataBindings.Add("Text", myBindingSource, "Address");
InitializationControl();
}
private void btnCancel_Click(object sender, EventArgs e)
{
ds.RejectChanges();
//ds.Clear();
da1.Fill(ds, "UserInfoDetail");
}
private void btnModify_Click(object sender, EventArgs e)
{
Control();
}
private void InitializationControl()
{
this.textBox1.ReadOnly = true;
this.textBox2.ReadOnly = true;
this.textBox3.ReadOnly = true;
this.textBox4.ReadOnly = true;
this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
}
private void Control()
{
this.textBox1.ReadOnly = false;
this.textBox2.ReadOnly = false;
this.textBox3.ReadOnly = false;
this.textBox4.ReadOnly = false;
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
}
private void btnSave_Click(object sender, EventArgs e)
{
if(this.btnSave.CanSelect==true)
{
Method.GetAccount g=new SchoolMate.Method.GetAccount();
Attribute.AccountInfo a=new SchoolMate.Attribute.AccountInfo();
a.Name=this.textBox1.Text;
a.Sex=this.textBox2.Text;
a.QQ=this.textBox3.Text;
a.Address=this.textBox4.Text;
if(g.AddUser(a)==1)
{
MessageBox.Show("已经成功修改信息!", "提示");
}
else
{
MessageBox.Show("修改失败!","提示");
}
}
}
private void btnClass_Click(object sender, EventArgs e)
{
this.Hide();
Windows.ClassInfo i = new ClassInfo();
i.Show();
}
private void btnPhoto_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Photo i = new Photo();
i.Show();
}
private void btnMessage_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Message i = new Message();
i.Show();
}
private void btnSearch_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Search i = new Search();
i.Show();
}
private void btnView_Click(object sender, EventArgs e)
{
}
}
}
我想问一下这段代码,为什么我在调试的时候它提示说:
this.textBox1.DataBindings.Add("Text", myBindingSource, "Name"); 这句代码
这将导致集合中的两个绑定绑定到同一个属性。
参数名: binding
是什么原因,如何解决?急!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;
namespace SchoolMate.Windows
{
public partial class UserInfo : Form
{
public UserInfo()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlConnection cn = null;
Link.SQLConnection sqlcn = new SchoolMate.Link.SQLConnection();
SqlDataAdapter da1;
BindingSource myBindingSource;
private void UserInfo_Load(object sender, EventArgs e)
{
cn = sqlcn.SQlconnection();
cn.Open();
da1 = new SqlDataAdapter("SELECT * FROM webapp.UserInfo", cn);
da1.Fill(ds, "UserInfo");
myBindingSource = new BindingSource();
myBindingSource.DataSource = ds.Tables["UserInfo"];
this.textBox1.DataBindings.Add("Text", myBindingSource, "Name");
this.textBox2.DataBindings.Add("Text", myBindingSource, "Sex");
this.dateTimePicker1.DataBindings.Add("Value", myBindingSource, "RegDate");
this.textBox3.DataBindings.Add("Text", myBindingSource, "QQ");
this.textBox4.DataBindings.Add("Text", myBindingSource, "Address");
InitializationControl();
}
private void btnCancel_Click(object sender, EventArgs e)
{
ds.RejectChanges();
//ds.Clear();
da1.Fill(ds, "UserInfoDetail");
}
private void btnModify_Click(object sender, EventArgs e)
{
Control();
}
private void InitializationControl()
{
this.textBox1.ReadOnly = true;
this.textBox2.ReadOnly = true;
this.textBox3.ReadOnly = true;
this.textBox4.ReadOnly = true;
this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
}
private void Control()
{
this.textBox1.ReadOnly = false;
this.textBox2.ReadOnly = false;
this.textBox3.ReadOnly = false;
this.textBox4.ReadOnly = false;
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
}
private void btnSave_Click(object sender, EventArgs e)
{
if(this.btnSave.CanSelect==true)
{
Method.GetAccount g=new SchoolMate.Method.GetAccount();
Attribute.AccountInfo a=new SchoolMate.Attribute.AccountInfo();
a.Name=this.textBox1.Text;
a.Sex=this.textBox2.Text;
a.QQ=this.textBox3.Text;
a.Address=this.textBox4.Text;
if(g.AddUser(a)==1)
{
MessageBox.Show("已经成功修改信息!", "提示");
}
else
{
MessageBox.Show("修改失败!","提示");
}
}
}
private void btnClass_Click(object sender, EventArgs e)
{
this.Hide();
Windows.ClassInfo i = new ClassInfo();
i.Show();
}
private void btnPhoto_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Photo i = new Photo();
i.Show();
}
private void btnMessage_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Message i = new Message();
i.Show();
}
private void btnSearch_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Search i = new Search();
i.Show();
}
private void btnView_Click(object sender, EventArgs e)
{
}
}
}
我想问一下这段代码,为什么我在调试的时候它提示说:
this.textBox1.DataBindings.Add("Text", myBindingSource, "Name"); 这句代码
这将导致集合中的两个绑定绑定到同一个属性。
参数名: binding
是什么原因,如何解决?急!
...全文
相关推荐
c# winform datagridview 绑定集合中对象属性
偶然从国外的网站上看到了一个方法可以绑定对象属性 通过DataPropertyName 支持' .' 的连接符,来连接对象属性,我修改了一下,可以用到项目中!
8、JavaFX 中的属性绑定与可观察集合
本文深入探讨了JavaFX中的属性绑定与可观察集合的使用。内容包括转换与格式化方法、使用Fluent API创建绑定、When类实现条件绑定、可观察集合概述、FXCollections类的工厂和实用方法、可观察集合的变更监听器,以及ListChangeListener中的变更事件处理。通过示例代码详细展示了如何在实际开发中应用这些功能,帮助开发者高效构建响应式JavaFX应用程序。
C#实现下拉框绑定list集合的方法
主要介绍了C#实现下拉框绑定list集合的方法,涉及C#中控件绑定的相关技巧,需要的朋友可以参考下
cxgrid动态增加列及属性绑定
cxgrid动态增加列及属性绑定
Spring Boot中的属性绑定的实现
主要介绍了Spring Boot中的属性绑定的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧


.NET Framework
