Click to See Complete Forum and Search --> : PropertyGrid doesn't load correct float[] property values


jit
March 24th, 2005, 01:47 AM
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

Norfy
March 24th, 2005, 01:53 AM
Does this happen at runtime as well?

jit
March 24th, 2005, 01:54 AM
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?

Norfy
March 24th, 2005, 02:00 AM
Does this make any difference?
[
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?

jit
March 24th, 2005, 02:11 AM
Does this make any difference?
[
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();
}
}
}
}

jit
March 24th, 2005, 02:37 AM
I found a MS Article about a similar problem with double array...

http://support.microsoft.com/default.aspx?scid=kb;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."

Norfy
March 24th, 2005, 02:45 AM
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.