Windows Develop Bookmark and Share   
 index > Windows Forms General > proerty grid display problem using ExpandableObjectConverter
 

proerty grid display problem using ExpandableObjectConverter

Hi, I am working on a simple project about graphs and it is already finished. I am now working on putting some comments and documentations to make it a readable code just in case. I read an article here in this forums about propery descriptions and i used it in my project. Everything was good and I was really amazed by the effect yet a problem occured. One of the class that I had created doesn`t give results as expexted. When i use [TypeConverter(typeof(ExpandableObjectConverter))] on a class with a certain number of properties, it must display the class in the property gid with a tree like implementation for setting the properties inside the class. But one of the class that i created does not do so. I had been creating different test to figure out what is the problem yet I haven`t figured it out..here is the class that i am reffering to.thanks and have a good day.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;

namespace MyGraph
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ChartView
{
public static readonly int DEFAULT_MARGIN = 5;
public static readonly int DEFAULT_LABEL_TO_AXIS_MARGIN = 5;

private float m_XMax = float.MaxValue;
private float m_XMin = float.MinValue;
private float m_XInterval = 1;
private int m_TopAxisMargin = DEFAULT_MARGIN;
private int m_XLabelToAxisMargin = DEFAULT_LABEL_TO_AXIS_MARGIN;
private TextStyle m_LabelStyle = new TextStyle();
private LineStyle m_XAxisLineStyle = LineStyle.Default;
private Dictionary<String, AxisView> m_YAxes = new Dictionary<string,AxisView>();

public ChartView()
{

}

public void AddYAxis(AxisView axis)
{
}

public void SetXAxisMinAndMax(float min, float max)
{
}


public float XMin
{
//get and set
}

public float XMax
{
//get and set
}

public float Interval
{
//get and set
}

public int TopAxisToMargin
{
//get and set
}

public int XLabelToAxisMargin
{
//get and set
}

//the other codes below are the same. get and set functions for property values
}
}
hanseh  Friday, October 19, 2007 2:28 AM
Thanks for the idea guys. I figured out the problem. Yes the null value causes the error in my class(the tree is not showing). Actually it is hard to figure since i am confident that it would not be null cause i always initialize objects. This is my solution... A simple solution only.

//////////////////////////////////////////////////////////////////////////////
public ChartView View
{
get
{
return m_View;
}
set
{
if (value != null)
m_View = value;
}
}
/////////////////////////////////////////////////////////////////////////////////

a null value check statement to assure that m_View will not be null. Any better approach?? thanks and GooDLuck

Simple mistakes tend to make people learn a lot.....
hanseh  Wednesday, October 24, 2007 1:06 AM

Hi, hanseh,

I tried your codes and they work well in my sample. (It can show a tree in PropertyGrid)

Could you please show us more codes and more details of what is going on in your application?

Regards

Yu Guo â€?MSFT  Monday, October 22, 2007 7:12 AM
Thank you for the reply. Lately I also tried to create a seperate project that uses the same class that I had mentioned and i was also suprised that it had work fine. So i came up with a theory that the problem is somewhere in my code. Maybe a certain event sets the whole class to null. I am now looking for the possible source of the problem. I am raising another question about expandable object types.Are there events that may remove or cause expandable declarations not to work?
hanseh  Tuesday, October 23, 2007 9:02 AM

Hi, hanseh,

I am not sure what do you mean of not to work.

Do you mean that you cannot see the tree in your PropertyGrid or you can see it but it does not work?

If the Object is not intialized(null), the tree may not appear.

So you should debug your application to see which makes your object to null.

Regards

Yu Guo â€?MSFT  Tuesday, October 23, 2007 9:21 AM
Thanks for the idea guys. I figured out the problem. Yes the null value causes the error in my class(the tree is not showing). Actually it is hard to figure since i am confident that it would not be null cause i always initialize objects. This is my solution... A simple solution only.

//////////////////////////////////////////////////////////////////////////////
public ChartView View
{
get
{
return m_View;
}
set
{
if (value != null)
m_View = value;
}
}
/////////////////////////////////////////////////////////////////////////////////

a null value check statement to assure that m_View will not be null. Any better approach?? thanks and GooDLuck

Simple mistakes tend to make people learn a lot.....
hanseh  Wednesday, October 24, 2007 1:06 AM

Hi, hanseh,

It is really great that you found a solution for your problem.

Because I don't see thecomplete codes of your application, I cannotdefinitely give yousome better approach.

But in my point of view, you solution should be among the best ones.

Regards.

Yu Guo â€?MSFT  Wednesday, October 24, 2007 1:28 AM
Thanks a lot Yu Guo....

Well, thanks again... I was planning to change my project schema before you sent your replies that made me think twice. Thanks a lot... Well, see yah again in the near future for a lot of upcoming problems.
hanseh  Wednesday, October 24, 2007 1:41 AM

You can use google to search for other answers

Custom Search

More Threads

• Using an embedded image for a button's background image
• Listview subitem text is not shown fully in the UI eventhough the length of the text is correct.
• How to add a child node to a TreeView using an index?
• how to set timeout for a thread
• Form losing focus after Messagebox.show("..")
• Catching the windows size of a MDI form
• DataGrid KeyPress
• customize menustrip
• BeforeCheckedChanged
• DataGridView, ValueType, and Format