private string theName = string.Empty;
private object theValue = null;
当theValue为数组时 这一栏就设置为下拉框 并把数组的值绑定到下拉框中
propertyg中每行前面一栏为theName的值 后面一栏为theValue的值
这个怎么实现 求大神指教
private object theValue = null;
当theValue为数组时 这一栏就设置为下拉框 并把数组的值绑定到下拉框中
propertyg中每行前面一栏为theName的值 后面一栏为theValue的值
这个怎么实现 求大神指教
解决方案 »
- 关于进程~~~~~~~~~~~
- C#windows服务
- 用C#怎样判断本机是否安装了OUTLOOK2003???
- 在dataGridView里选定一行记录,如何将选定记录里的各项值传到对应的TextBox里?
- 在C#中怎样查找窗体中的控件??
- 删除datagrid选中的那一行数据
- 谁有精简版下的日期控件,急啊!!!
- DataGrid到底如何修改列头啊?
- (水贴)CLR via c# 中文版第四版谁在翻译呀,啥时候出
- 怎么使用LINQ实现对List<List<string>>循环并拼接字符串
- C#调用dll输出string乱码
- 如何取得DataGridViewComboBoxColumn选择行的值
属性2 | 数组1(下拉框显示)
属性3 | 数组3(下拉框显示)
我的意思就是属性1,属性2等也是数据绑定的 后边的也是绑定的 属性1这些是theName的值 数组这些都是 theValue的值 我把代码贴出来谢谢帮忙 谢谢
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;namespace EX1
{
public class Demo
{
private object[] obj;
public static string prophead = string.Empty;
public object propvaule;
//Demo de = new Demo(); public Demo() { }
public Demo(object[] obj)
{
prophead = obj[0].ToString();
propvaule = obj[1];
} private int theCountry;
private bool theLanguage; [CategoryAttribute("基本信息"), DescriptionAttribute("如果你要将用户设置为删除状态,请选择“是”"), DisplayName("删除状态")]
[TypeConverter(typeof(Class2))]
public int Country
{
get
{
return theCountry;
}
set
{
theCountry = value;
}
} [CategoryAttribute("基本信息"), DescriptionAttribute("如果你要将用户设置为锁定状态,请选择“是”"), DisplayName("锁定状态")]
public bool Language
{
get
{
return theLanguage;
}
set
{
theLanguage = value;
}
} [CategoryAttribute("基本信息"), DescriptionAttribute("如果你要将用户设置为锁定状态,请选择“是”"), DisplayName("Location")]
public object Obj
{
get
{
return propvaule;
}
set
{
propvaule = value;
} }
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;namespace EX1
{
public class Class2 : ComboBoxItemTypeConvert
{
Hashtable hash = new Hashtable();
public override void GetConvertHash()
{ _hash = this.hash;
//_hash.Add("零", 0);
//_hash.Add("一", 1);
//_hash.Add("二", 2);
//_hash.Add("三", 3);
//_hash.Add("四", 4);
}
public void ListToHash(string[] list)
{
for (int i = 0; i < list.Length; i++)
{
hash.Add(list[i].ToString(), i);
}
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections;namespace EX1
{
public abstract class ComboBoxItemTypeConvert : TypeConverter
{
public Hashtable _hash; public abstract void GetConvertHash(); public ComboBoxItemTypeConvert()
{
_hash = new Hashtable();
GetConvertHash();
} public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
} public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
string[] ids = new string[_hash.Values.Count]; int i = 0;
foreach (DictionaryEntry myDE in _hash)
{
ids[i++] = (string)(myDE.Key);
} return new StandardValuesCollection(ids);
} public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true; return base.CanConvertFrom(context, sourceType);
} public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
foreach (DictionaryEntry myDe in _hash)
{
if (myDe.Key.Equals(value))
return myDe.Value;
}
}
return base.ConvertFrom(context, culture, value);
} public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v, Type destinationType)
{
if (destinationType == typeof(string))
{
foreach (DictionaryEntry myDE in _hash)
{
if (myDE.Value.Equals(v))
return myDE.Key.ToString();
}
}
return base.ConvertTo(context, culture, v, destinationType); } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
}
}
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;
using System.Xml;
using DevComponents.DotNetBar;namespace EX1
{
public partial class Form1 : Form
{
XmlDocument mXDoc = new XmlDocument();
public Form1()
{
InitializeComponent();
Load();
//Demo o = new Demo();
//this.advPropertyGrid1.SelectedObject= o; //”propertyGrid1“为PropertyGrid控件
}
public void Load()
{ mXDoc.Load(Application.StartupPath + "/xmlPropertyInfo.xml");
GetProperty();
} public void GetProperty()
{
XmlNode tmpXNode = mXDoc.SelectSingleNode("PropertyInfo/Propertys[@GroupID=\"1\"]");
XmlNodeList tmpXPropLst = tmpXNode.SelectNodes("Property"); AdvPropertyGrid progrid = new AdvPropertyGrid();
progrid = this.advPropertyGrid1; foreach (XmlNode node in tmpXPropLst)
{
Class2 ex = new Class2();
object[] list = new object[2];
Demo de = new Demo(); list[0] = node.Attributes["PropertyName"].Value;
if (node.Attributes["PropertyValue"] != null)
{
list[1] = node.Attributes["PropertyValue"].Value;
de.Obj = node.Attributes["PropertyValue"].Value;
progrid.SelectedObject = de;
}
else
{
string[] str= GetValueList(node.Attributes["ListId"].Value);
list[1]=str;
ex.ListToHash((string[])list[1]);
progrid.SelectedObject = new Demo((string[])list[1]);
}
}
} public string[] GetValueList(string ListId)
{
XmlNode tmpXNode = mXDoc.SelectSingleNode("PropertyInfo/ValueList[@ListId=\"" + ListId + "\"]");
XmlNodeList tmpXPropLst = tmpXNode.SelectNodes("List");
string[] valueList = new string[tmpXPropLst.Count];
int i = 0;
foreach (XmlNode node in tmpXPropLst)
{
string strValue = node.Attributes["PropertyValue"].Value;
valueList[i] = strValue;
i++;
}
return valueList;
}
}
}
<PropertyInfo>
<Propertys GroupID="1">
<Property PropertyName="属性1" PropertyValue="背影色"/>
<Property PropertyName="属性2" PropertyValue="太坑爹了"/>
<Property PropertyName="属性3" PropertyValue="字体"/>
<Property PropertyName="属性4" ListId="2" />
<Property PropertyName="属性5" PropertyValue="内容" />
<Property PropertyName="ScrollBars" PropertyValue="滚动条" />
<Property PropertyName="TextAlign" PropertyValue="文本对齐" />
<Property PropertyName="Multline" PropertyValue="多行" />
<Property PropertyName="PasswordChar" PropertyValue="密码文本" />
<Property PropertyName="Size" PropertyValue="大小" />
<Property PropertyName="Location" PropertyValue="位置" />
</Propertys> <ValueList ListId="1">
<List PropertyValue="可选值1"/>
<List PropertyValue="可选值2"/>
<List PropertyValue="可选值3"/>
<List PropertyValue="可选值4"/>
</ValueList>
<ValueList ListId="2">
<List PropertyValue="可选值5"/>
<List PropertyValue="可选值6"/>
<List PropertyValue="可选值7"/>
<List PropertyValue="可选值8"/>
</ValueList>
</PropertyInfo>
52 TypeConverter(typeof(MyConverter)), ListAttribute( new string[] { "张三", "李四", "王五", "赵六", "马七" })] 这里面的这个数组可以写活吗? 可以传一个数组进去不 这种东西我不是很懂 谢谢你
private static string[] strArray = new string[] { "张三", "李四", "王五", "赵六", "马七" }; [CategoryAttribute("信息"), DescriptionAttribute("姓名"),
TypeConverter(typeof(MyConverter)), ListAttribute(strArray)]
public string Name
{
get { return _name; }
set { _name = value; }
}
}
不能传数组进去
错误 1 特性实参必须是特性形参类型的常量表达式、typeof 表达式或数组创建表达式
”不就是说要给一个theName就添加一行栏目吗?那就完全和类的绑定无关了。对于自定义属性编辑器,继承UITypeEditor即可,而你这里是对数组的下拉框,则是继承ObjectSelectorEditor 并重写FillTreeWithData方法,对于上面给出的继承TypeConverter虽然看似达到了目的,其实并非理想,理想的应该使用Edit特性,如:
[Editor(typeof(SysMenuSelectorEditor), typeof(UITypeEditor))] internal class SysMenuSelectorEditor : ObjectSelectorEditor
{
protected override void FillTreeWithData(Selector theSel,
ITypeDescriptorContext theCtx, IServiceProvider theProvider)
{
base.FillTreeWithData(theSel, theCtx, theProvider); //clear the selection theSel.Nodes.Add(new SelectorNode("(无)", ""));
if (CommonData.sysmenus != null)
foreach (String aIt in CommonData.sysmenus.Keys)
{
SelectorNode aNd = new SelectorNode(aIt, aIt); theSel.Nodes.Add(aNd); if (aIt == (String)theCtx.PropertyDescriptor.GetValue(theCtx.Instance))
theSel.SelectedNode = aNd;
}
}
}
这里可以大作文章啊。比如传入 xpath,到指定的xml读取。
或者获得某个静态类的数组返回。public class ListAttribute : Attribute
{
public string[] _lst;
public ListAttribute(string[] lst)
{
//初始化列表值
_lst = new[] {"1", "3", "4"};
}
}