Need an attribute to hide a field when databinding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • moondaddy

    Need an attribute to hide a field when databinding

    using c# 3.5 I have list of business objects which I will use in lists for
    databinding and I want to hide some of the fields so they don't show up in
    the list control.

    some of my list will be:
    List<someClassl ist
    Observable collections
    and
    a custom list derived from the BindingList.

    [someAttribute]
    public int SomeField
    {
    get...
    set...
    }

    Thanks.


    --
    moondaddy@newsg roup.nospam


  • Zhi-Xin Ye [MSFT]

    #2
    RE: Need an attribute to hide a field when databinding

    Dear moondaddy,

    As I understand, you have a list of business objects, when performing data
    binding, you want some of the properties in the custom class not be
    displayed in the list control.

    You can use the Browsable attribute, setting it to false would make the
    property hidden when performing data binding. e.g.

    ============== Code Sample ===============

    class Customer
    {
    private int id;
    private string name;
    private string coutry;

    public Customer(int id, string name, string coutry)
    {
    this.id = id;
    this.name = name;
    this.coutry = coutry;
    }

    public int ID
    {
    get { return id; }
    set { this.id = value; }
    }

    [Browsable(false )]
    public string Name
    {
    get { return name; }
    set { this.name = value; }
    }

    public string Country
    {
    get { return coutry; }
    set { this.coutry = value; }
    }
    }

    private void Form2_Load(obje ct sender, EventArgs e)
    {
    List<Customerar r = new List<Customer>( );
    arr.Add(new Customer(1, "Zhang", "China"));
    arr.Add(new Customer(2, "John", "US"));
    arr.Add(new Customer(3, "Ricky", "UK"));
    arr.Add(new Customer(4, "Hkjer", "UK"));
    arr.Add(new Customer(5, "Rbtrw", "DE"));
    arr.Add(new Customer(6, "Ricky", "AU"));
    arr.Add(new Customer(7, "Griao", "FR"));

    this.dataGridVi ew1.DataSource = arr;
    }

    =============== =============== ===============

    When running the code, you'll find the "Name" property is not displayed in
    the DataGridView.

    Should you have any questions, please feel free to let me know.

    Sincerely,
    Zhi-Xin Ye
    Microsoft Managed Newsgroup Support Team

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    msdnmg@microsof t.com.

    =============== =============== =============== =====
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subs...#notifications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://support.microsoft.com/select/...tance&ln=en-us.
    =============== =============== =============== =====
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • Marc Gravell

      #3
      Re: Need an attribute to hide a field when databinding

      For the UI: [Browsable(false )]

      For intellisense: [EditorBrowsable (blah.Never)]

      Marc

      Comment

      • moondaddy

        #4
        Re: Need an attribute to hide a field when databinding

        Thanks,

        I tested this and it did work in a winforms app, but doesnt work in a wpf
        app. I should have specified that I was working in wpf, but I didnt think
        it made a difference until now. Do you know what I need to do to make this
        work in wpf?


        "Zhi-Xin Ye [MSFT]" <v-zhye@online.mic rosoft.comwrote in message
        news:ZgO1nO6HJH A.1656@TK2MSFTN GHUB02.phx.gbl. ..
        Dear moondaddy,
        >
        As I understand, you have a list of business objects, when performing data
        binding, you want some of the properties in the custom class not be
        displayed in the list control.
        >
        You can use the Browsable attribute, setting it to false would make the
        property hidden when performing data binding. e.g.
        >
        ============== Code Sample ===============
        >
        class Customer
        {
        private int id;
        private string name;
        private string coutry;
        >
        public Customer(int id, string name, string coutry)
        {
        this.id = id;
        this.name = name;
        this.coutry = coutry;
        }
        >
        public int ID
        {
        get { return id; }
        set { this.id = value; }
        }
        >
        [Browsable(false )]
        public string Name
        {
        get { return name; }
        set { this.name = value; }
        }
        >
        public string Country
        {
        get { return coutry; }
        set { this.coutry = value; }
        }
        }
        >
        private void Form2_Load(obje ct sender, EventArgs e)
        {
        List<Customerar r = new List<Customer>( );
        arr.Add(new Customer(1, "Zhang", "China"));
        arr.Add(new Customer(2, "John", "US"));
        arr.Add(new Customer(3, "Ricky", "UK"));
        arr.Add(new Customer(4, "Hkjer", "UK"));
        arr.Add(new Customer(5, "Rbtrw", "DE"));
        arr.Add(new Customer(6, "Ricky", "AU"));
        arr.Add(new Customer(7, "Griao", "FR"));
        >
        this.dataGridVi ew1.DataSource = arr;
        }
        >
        =============== =============== ===============
        >
        When running the code, you'll find the "Name" property is not displayed in
        the DataGridView.
        >
        Should you have any questions, please feel free to let me know.
        >
        Sincerely,
        Zhi-Xin Ye
        Microsoft Managed Newsgroup Support Team
        >
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/en-us/subs...#notifications.
        >
        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://support.microsoft.com/select/...tance&ln=en-us.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no
        rights.
        >

        Comment

        • Zhi-Xin Ye [MSFT]

          #5
          Re: Need an attribute to hide a field when databinding

          Dear moondaddy,

          As far as I know there is not such an attribute in WPF. However, if you
          don't want to show the field in the control, you can just don't assign that
          field for the DisplayMemberBi nding or DisplayMemberPa th property. Could you
          please explain your scenario in more details?

          I look forward to your reply.

          Sincerely,
          Zhi-Xin Ye
          Microsoft Managed Newsgroup Support Team

          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          • moondaddy

            #6
            Re: Need an attribute to hide a field when databinding

            DisplayMemberBi nding or DisplayMemberPa th properties don't apply here. I
            have a grid (in this case its a grid from Infragistics) and set its data
            source like this:

            grid.DataSource = myList;

            and I waned to use an attribute to hide some of the props in the business
            objects in myList. I even tried the observablecolle ction with no luck.


            "Zhi-Xin Ye [MSFT]" <v-zhye@online.mic rosoft.comwrote in message
            news:nFDXnGgIJH A.1656@TK2MSFTN GHUB02.phx.gbl. ..
            Dear moondaddy,
            >
            As far as I know there is not such an attribute in WPF. However, if you
            don't want to show the field in the control, you can just don't assign
            that
            field for the DisplayMemberBi nding or DisplayMemberPa th property. Could
            you
            please explain your scenario in more details?
            >
            I look forward to your reply.
            >
            Sincerely,
            Zhi-Xin Ye
            Microsoft Managed Newsgroup Support Team
            >
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.
            >
            This posting is provided "AS IS" with no warranties, and confers no
            rights.
            >

            Comment

            • Zhi-Xin Ye [MSFT]

              #7
              Re: Need an attribute to hide a field when databinding

              Dear moondaddy,

              I'm not familiar with the infragistics DataGrid, but as far as I know
              there's no such attribute in WPF. Would you mind trying in another way? For
              example, you can hide the fields which you don't need from the grid. I
              find some threads on the internet on how to hide a field from the
              Infragistics DataGrid.

              Threads for your information:

              Using xamdatagrid to hide columns programmically


              how to control columns display when displaying hierarchical data using
              XamDataGrid


              Should you have any questions, please don't hesitate to let me know.

              Sincerely,
              Zhi-Xin Ye
              Microsoft Managed Newsgroup Support Team

              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.

              This posting is provided "AS IS" with no warranties, and confers no rights.


              Comment

              • moondaddy

                #8
                Re: Need an attribute to hide a field when databinding

                Thanks,

                Yes I can write code to hide those columns in the grid, but I was hoping I
                could use an attribute. I codegen my custom list classes and it's real easy
                to assign attributes in the code generator. if I know ahead of time what
                properties I don't want to be visible in the UI, I can just assign the
                attribute to the property or field one time and then when every the business
                object is used in a list, I only see what I want to see. This greatly
                simplifies things.

                Thanks again.


                "Zhi-Xin Ye [MSFT]" <v-zhye@online.mic rosoft.comwrote in message
                news:lLnxvTrKJH A.6004@TK2MSFTN GHUB02.phx.gbl. ..
                Dear moondaddy,
                >
                I'm not familiar with the infragistics DataGrid, but as far as I know
                there's no such attribute in WPF. Would you mind trying in another way?
                For
                example, you can hide the fields which you don't need from the grid. I
                find some threads on the internet on how to hide a field from the
                Infragistics DataGrid.
                >
                Threads for your information:
                >
                Using xamdatagrid to hide columns programmically

                >
                how to control columns display when displaying hierarchical data using
                XamDataGrid

                >
                Should you have any questions, please don't hesitate to let me know.
                >
                Sincerely,
                Zhi-Xin Ye
                Microsoft Managed Newsgroup Support Team
                >
                Delighting our customers is our #1 priority. We welcome your comments and
                suggestions about how we can improve the support we provide to you. Please
                feel free to let my manager know what you think of the level of service
                provided. You can send feedback directly to my manager at:
                msdnmg@microsof t.com.
                >
                This posting is provided "AS IS" with no warranties, and confers no
                rights.
                >
                >

                Comment

                • Zhi-Xin Ye [MSFT]

                  #9
                  Re: Need an attribute to hide a field when databinding

                  Dear moondaddy,

                  Yes I know it would make things easy if we had an attribute to hide the
                  field when binding, I would suggest you post this feature as a suggestion
                  to our Connect feedback portal. Our developer
                  will evaluate it seriously and take them into consideration when designing
                  furture release of the product.

                  Here is the link for the Connect feedback portal:

                  They've got long beards, red hats, and a knack for


                  For the time being, you can write code to hide the columns in the grid,
                  sorry for any inconvenience this may cause.

                  Sincerely,
                  Zhi-Xin Ye
                  Microsoft Managed Newsgroup Support Team

                  Delighting our customers is our #1 priority. We welcome your comments and
                  suggestions about how we can

                  improve the support we provide to you. Please feel free to let my manager
                  know what you think of the level

                  of service provided. You can send feedback directly to my manager at:
                  msdnmg@microsof t.com.

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  Comment

                  • moondaddy

                    #10
                    Re: Need an attribute to hide a field when databinding

                    Will do. Thanks.

                    "Zhi-Xin Ye [MSFT]" <v-zhye@online.mic rosoft.comwrote in message
                    news:wYgQIxCMJH A.4620@TK2MSFTN GHUB02.phx.gbl. ..
                    Dear moondaddy,
                    >
                    Yes I know it would make things easy if we had an attribute to hide the
                    field when binding, I would suggest you post this feature as a suggestion
                    to our Connect feedback portal. Our developer
                    will evaluate it seriously and take them into consideration when designing
                    furture release of the product.
                    >
                    Here is the link for the Connect feedback portal:
                    >
                    They've got long beards, red hats, and a knack for

                    >
                    For the time being, you can write code to hide the columns in the grid,
                    sorry for any inconvenience this may cause.
                    >
                    Sincerely,
                    Zhi-Xin Ye
                    Microsoft Managed Newsgroup Support Team
                    >
                    Delighting our customers is our #1 priority. We welcome your comments and
                    suggestions about how we can
                    >
                    improve the support we provide to you. Please feel free to let my manager
                    know what you think of the level
                    >
                    of service provided. You can send feedback directly to my manager at:
                    msdnmg@microsof t.com.
                    >
                    This posting is provided "AS IS" with no warranties, and confers no
                    rights.
                    >

                    Comment

                    Working...