DataMember属性"类型"不能在数据源中发现 [英] DataMember property "Type" cannot be found on the DataSource

查看:149
本文介绍了DataMember属性"类型"不能在数据源中发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建XML反序列化以下类:

I have create the following class for XML deserialization:

[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class ProgrammingConfiguration
{
    private uint versionField;
    private byte[] eLFImageField;
    private PreferenceType[] preferencesField;
    private ProgrammingConfigurationProtectFlashAfterProgramming   protectFlashAfterProgrammingField;

    //XML version
    public uint Version
    {
        get { return this.versionField; }
        set { this.versionField = value; }
    }

    //ELF image
    [System.Xml.Serialization.XmlElementAttribute(DataType = "base64Binary")]
    public byte[] ELFImage
    {
        get { return this.eLFImageField; }
        set { this.eLFImageField = value; }
    }

    //Preference
    [System.Xml.Serialization.XmlArrayItemAttribute("Preference", IsNullable = false)]
    public PreferenceType[] Preferences
    {
        get { return this.preferencesField; }
        set { this.preferencesField = value; }
    }

    //Protect flash after programming
    public ProgrammingConfigurationProtectFlashAfterProgramming ProtectFlashAfterProgramming
    {
        get { return this.protectFlashAfterProgrammingField; }
        set { this.protectFlashAfterProgrammingField = value; }
    }
}

//Preference Type
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class PreferenceType
{
    private string tagField;
    private PreferenceTypePrecedence precedenceField;
    private ValueType valueField;

    public string Tag
    {
        get { return this.tagField; }
        set { this.tagField = value; }
    }

    public PreferenceTypePrecedence Precedence
    {
        get { return this.precedenceField; }
        set { this.precedenceField = value; }
    }

    public ValueType Value
    {
        get { return this.valueField; }
        set { this.valueField = value; }
    }
}

//Precedence Type
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum PreferenceTypePrecedence
{
    XML,
    [System.Xml.Serialization.XmlEnumAttribute("Target,XML")]
    TargetXML,
    Target,
}

//Value Type
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class ValueType
{
    private string lengthField;
    private object itemField;
    private ItemChoiceType itemElementNameField;

    [System.Xml.Serialization.XmlElementAttribute(DataType = "integer")]
    public string Length
    {
        get { return this.lengthField; }
        set { this.lengthField = value; }
    }

    [System.Xml.Serialization.XmlElementAttribute("AutoIncrement", typeof(ValueTypeAutoIncrement))]
    [System.Xml.Serialization.XmlElementAttribute("HexBinary", typeof(string))]
    [System.Xml.Serialization.XmlElementAttribute("Integer", typeof(string))]
    [System.Xml.Serialization.XmlElementAttribute("String", typeof(string))]
    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
    public object Item
    {
        get { return this.itemField; }
        set { this.itemField = value; }
    }

    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public ItemChoiceType ItemElementName
    {
        get { return this.itemElementNameField; }
        set { this.itemElementNameField = value; }
    }
}

//Autoincrement data
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class ValueTypeAutoIncrement
{
    private string minimumField;
    private string maximumField;
    private ValueTypeAutoIncrementOverflowBehaviour overflowBehaviourField;

    public string Minimum
    {
        get { return this.minimumField; }
        set { this.minimumField = value; }
    }

    public string Maximum
    {
        get { return this.maximumField; }
        set { this.maximumField = value; }
    }

    public ValueTypeAutoIncrementOverflowBehaviour OverflowBehaviour
    {
        get { return this.overflowBehaviourField; }
        set { this.overflowBehaviourField = value; }
    }
}

//Overflow behaviour
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum ValueTypeAutoIncrementOverflowBehaviour
{
    Wrap,
    Exception,
}

//Data type
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema = false)]
public enum ItemChoiceType
{
    AutoIncrement,
    HexBinary,
    Integer,
    String,
}

//ProtectFlashAfterProgramming
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum ProgrammingConfigurationProtectFlashAfterProgramming
{
    True,
    False,
}

我要创建2绑定源,一个datagridview的,一个是文本框。我曾尝试以下内容:

I want to create 2 binding source, one for datagridview and one for textbox. I have tried the following:

        ProgrammingConfiguration pc = new ProgrammingConfiguration();

        XmlSerializer serializer = new XmlSerializer(typeof(ProgrammingConfiguration));

        //Reading the XML document requires a FileStream.            
        Stream reader = new FileStream(filename, FileMode.Open);

        //Call the Deserialize method to restore the object's state.
        pc = (ProgrammingConfiguration)serializer.Deserialize(reader);

        reader.Close();

        bindingsource.DataSource = pc;
        bindingsource.DataMember = "Preferences";


        bsV.DataSource = bindingsource;
        bsV.DataMember = "ItemElementName";



程序无法在该行bsV.DataMember =ItemElementName运行。任何建议,请

The program failed to run at the line bsV.DataMember = "ItemElementName". Any suggestion please

推荐答案

变化:

bindingsource.DataSource = pc;



to:

bindingsource.DataSource = new List { pc };



我不知道为什么,但PropertyManager中犯规像链接的属性,但是确实的CurrencyManager。使用一个IEnumerable会愚弄和强制的BindingContext创建的CurrencyManager而不是PropertyManager中它是结合单个对象。涉及到的BindingSource问题心不是你可以设置网格列表和DataMember的首选项,而不是DataSource属性。

i dont know why but PropertyManager doesnt like chaining properties, however CurrencyManager does. using an IEnumerable will fool and force the BindingContext create CurrencyManager instead of PropertyManager which is for binding single object. the issue isnt related to BindingSource you could set the DataSource property of the grid to the list and DataMember to the Preferences instead.

你没有使用的BindingSource绑定到。无论是文本框

you dont have to use BindingSource to bind to the textbox either.

简单的使用:

textBox.DataBindings.Add(list, "Preferences.ItemElementName");



作为Value.Maximum上的使用方法:

as for Value.Maximum use on of the:

textBoxMaximum.DataBindings.Add(list, Preferences.Value.Maximum);
textBoxMaximum.DataBindings.Add(bindingSource, Value.Maximum);

这篇关于DataMember属性"类型"不能在数据源中发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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