数据绑定的问题 可以把数据源的字段绑定到TextBox的Text属性上,应该可以把数据源的字段绑定到BackColor属性上吧。checked属性绑定,试试1,0 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如下textBox1.DataBindings.Add("Text",ds,"Customers.customerID");ChecBox.DataBindings.Add("Cheched",ds,"Customers.YesNo"); ChecBox.DataBindings.Add("Cheched",ds,"Customers.YesNo");已经实现了,我用的Customers.YesNo是"false"&"true".但ChecBox.DataBindings.Add("BackColor",ds,"MYCOLOR")依旧不正确.数据库中的数据是"Color.Blue","Color.Black",System.Drawing的命名空间我已经申明了.我也尝试将数据库中的数据改成"Blue","Black",或者是"107, 137, 210",但是一直都是捕获这样的错误类型System.InvalidCastException.搞不懂~ 有趣的问题 实际上还是蛮简单的 报错是肯定会的因为类型不符 解决的方法就是利用Binding.Format event 将数据转换成正确的类型Example:Table : ID COLOR 1 BLACK 2 WHITE 3 RED 4 GREEN ....在程序中Binding bind = new Binding("BackColor", this.ds, "colors.color")bind.Format +=new ConvertEventHandler(ConvertStringToColor);private void ConvertStringToColor(object sender, ConvertEventArgs e){ if(e.DesiredType == typeof(Color)){ Color targetColor = Color.FromName((string)e.Value); e.Value = targetColor; }}this.label1.DataBindings.Add(bind);---DoneParse 和 Format 是Binding类中比较常用的 尤其是显示自定义类型的时候 问一个级联查询的sql 这个到底错在哪里了呢? 如何在GridView 或 DataGrid中实现 选中行上下移动 不同站点之间的跳转 使用ListView如何达到Windows资源管理器中显示文件夹和文件一样的功能?不同类型的文件的图标不一样,使用本机关联的文件类型图标! 大虾请进 C# 用Process.Start()会出现打开的程序无法访问网络 关于static类型的问题! 怎样得到活动窗口中的具体内容 AquaSample按钮,不响应原来的鼠标事件 c#中,怎么得到系统目录? 在哪儿能找到 Visual Sourcesafe 的服务器端安装程序
textBox1.DataBindings.Add("Text",ds,"Customers.customerID");
ChecBox.DataBindings.Add("Cheched",ds,"Customers.YesNo");
数据库中的数据是"Color.Blue","Color.Black",System.Drawing的命名空间我已经申明了.
我也尝试将数据库中的数据改成"Blue","Black",或者是"107, 137, 210",但是一直都是捕获这样的错误类型System.InvalidCastException.搞不懂~
解决的方法就是利用Binding.Format event 将数据转换成正确的类型
Example:
Table : ID COLOR
1 BLACK
2 WHITE
3 RED
4 GREEN
....在程序中
Binding bind = new Binding("BackColor", this.ds, "colors.color")
bind.Format +=new ConvertEventHandler(ConvertStringToColor);private void ConvertStringToColor(object sender, ConvertEventArgs e){
if(e.DesiredType == typeof(Color)){
Color targetColor = Color.FromName((string)e.Value);
e.Value = targetColor;
}
}
this.label1.DataBindings.Add(bind);---
DoneParse 和 Format 是Binding类中比较常用的 尤其是显示自定义类型的时候