CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2005
    Posts
    8

    PropertyGrid doesn't load correct float[] property values

    I have a strange problem.
    I have defined a windows component class in which there is a float [] private member like this:


    private float [] m_Directions = new float[] {0,1,2};

    Then I have created a property for setting and retrieving values of such a member, with designer support, like this:

    [
    Browsable(true),
    Category("Blend settings")
    ]
    public float[] Directions
    {
    get
    {
    return m_directions;
    }
    set
    {
    m_directions = value;
    }
    }

    When I am in design mode, setting of float[] goes well, (and I find updated values in InitializeComponent() method. Correct!

    When I shutdown .NET Devenv and then reopen my project, designer doesn't load
    the last values for m_Directions array, but the old ones {0,1,2}. Why?
    Is there a way to tell designer to load values from InitializeComponent() method?

    Any idea?
    thank you very much in advance!

    JIT

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: PropertyGrid doesn't load correct float[] property values

    Does this happen at runtime as well?
    Useful? Then click on (Rate This Post) at the top of this post.

  3. #3
    Join Date
    Mar 2005
    Posts
    8

    Re: PropertyGrid doesn't load correct float[] property values

    Quote Originally Posted by Norfy
    Does this happen at runtime as well?
    No, at runtime everything is correct.
    I would like to tell designer to reload new values when devent loads, from InitializeComponents(), ... but how?

  4. #4
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: PropertyGrid doesn't load correct float[] property values

    Does this make any difference?
    Code:
    [
    Browsable(true),
    Category("Blend settings")
    ]
    public float[] Directions
    {
        get
        {
            return m_directions;
        }
        set
        {
            m_directions = value;
           Invalidate(); 
        }
    }
    If not can you post (or email) a complete component?
    Useful? Then click on (Rate This Post) at the top of this post.

  5. #5
    Join Date
    Mar 2005
    Posts
    8

    Re: PropertyGrid doesn't load correct float[] property values

    Quote Originally Posted by Norfy
    Does this make any difference?
    Code:
    [
    Browsable(true),
    Category("Blend settings")
    ]
    public float[] Directions
    {
        get
        {
            return m_directions;
        }
        set
        {
            m_directions = value;
           Invalidate(); 
        }
    }
    If not can you post (or email) a complete component?

    Same problem. This is my component (a simple Panel):

    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Diagnostics;

    namespace WinApp
    {
    /// <summary>
    /// Summary description for MyPanel.
    /// </summary>
    public class MyPanel : System.Windows.Forms.Panel
    {
    private float [] m_directions = new float[]{0,0,1};
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public MyPanel(System.ComponentModel.IContainer container)
    {
    ///
    /// Required for Windows.Forms Class Composition Designer support
    ///
    container.Add(this);
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    }

    public MyPanel()
    {
    ///
    /// Required for Windows.Forms Class Composition Designer support
    ///
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }


    #region Component Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    components = new System.ComponentModel.Container();
    }
    #endregion

    [
    Browsable(true),
    Category("Blend settings")
    ]
    public float[] Directions
    {
    get
    {
    return m_directions;
    }
    set
    {
    m_directions = value;
    Invalidate();
    }
    }
    }
    }

  6. #6
    Join Date
    Mar 2005
    Posts
    8

    Re: PropertyGrid doesn't load correct float[] property values

    I found a MS Article about a similar problem with double array...

    http://support.microsoft.com/default...b;EN-US;832924

    In fact 2 minutes ago I noticed the following error at design time:

    " At least one element in the source array could not be cast down to the destination array type."

  7. #7
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: PropertyGrid doesn't load correct float[] property values

    I noticed the design time error message as well.

    I know the bug report mentions some workarounds, but Instead of using float/double you could also use int and express your values as percentages.
    Useful? Then click on (Rate This Post) at the top of this post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured