issue in property window

A

--== Alain ==--

Hi,

I've created a simple class "GridLines" having 3 properties (Prop1,
Prop2, and Prop3).

in my custom control, i've created a property based on this class
"GridLines".

To show the GridLines properties as my custom control subproperties, i
used an expandable ExpandableObjectConverter class for my GridLineConverter.

therefore in my custom control property window, i have the following thing :

GridLines = Prop1_value, Prop2_value, Prop3_value
- Prop1 : value
- Prop2 : value
- Prop3 : value

Everything works well if i use my custom control subproperties (Prop1,
Prop2, Prop3) to setup the GridLine property (BTW, GridLine property
value is a string).

However, if i type directly to GridLine property field "Prop1_value,
Prop2_Value, Prop3_value", my component raises an error message. I've
checked several times my code, but i must be blind because o do not see
any error.

here is the piece of code which raises the error :

public CGridLine ConvertFromString(object value)
{
string[] values = ((string)value).Split(',');
if (values.Length != 3)
throw new ArgumentException("Could not convert the value !");
try
{
CGridLine GridLine = new CGridLine();
ColorConverter ColorConverter = new ColorConverter();
StringConverter StringConverter = new StringConverter();

GridLine.Lines =
(GridLines)StringConverter.ConvertFromString(values[0]);
GridLine.Style =
(GridLineStyle)StringConverter.ConvertFromString(values[1]);
GridLine.Color =
(Color)ColorConverter.ConvertFromString(values[2]);

// Convert the name of the enumerated value into the corresponding
// enumerated value (which is actually an integer constant).

return GridLine;
}
catch (Exception err)
{
throw new ArgumentException("Could not convert the value \n\n
Error Message : " + err.Message);
}
}
 
A

--== Alain ==--

Hi Guys,

i found the problem.
Prop1 and Prop2 are enum types, therefore i had to use :
my_GridLine.Style = (GridLineStyle)Enum.Parse(typeof(GridLineStyle),
values[1], true);

instead of :
GridLine.Style =
(GridLineStyle)StringConverter.ConvertFromString(values[1]);

Al.

--== Alain ==-- said:
Hi,

I've created a simple class "GridLines" having 3 properties (Prop1,
Prop2, and Prop3).

in my custom control, i've created a property based on this class
"GridLines".

To show the GridLines properties as my custom control subproperties, i
used an expandable ExpandableObjectConverter class for my
GridLineConverter.

therefore in my custom control property window, i have the following
thing :

GridLines = Prop1_value, Prop2_value, Prop3_value
- Prop1 : value
- Prop2 : value
- Prop3 : value

Everything works well if i use my custom control subproperties (Prop1,
Prop2, Prop3) to setup the GridLine property (BTW, GridLine property
value is a string).

However, if i type directly to GridLine property field "Prop1_value,
Prop2_Value, Prop3_value", my component raises an error message. I've
checked several times my code, but i must be blind because o do not see
any error.

here is the piece of code which raises the error :

public CGridLine ConvertFromString(object value)
{
string[] values = ((string)value).Split(',');
if (values.Length != 3)
throw new ArgumentException("Could not convert the value !");
try
{
CGridLine GridLine = new CGridLine();
ColorConverter ColorConverter = new ColorConverter();
StringConverter StringConverter = new StringConverter();

GridLine.Lines =
(GridLines)StringConverter.ConvertFromString(values[0]);
GridLine.Style =
(GridLineStyle)StringConverter.ConvertFromString(values[1]);
GridLine.Color =
(Color)ColorConverter.ConvertFromString(values[2]);

// Convert the name of the enumerated value into the corresponding
// enumerated value (which is actually an integer constant).

return GridLine;
}
catch (Exception err)
{
throw new ArgumentException("Could not convert the value \n\n
Error Message : " + err.Message);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top