By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

Custom properties

P: n/a
I have created a control and added a few properties. One of these is an
array of DateTime objects, looking like this:

[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
Description("whatever"), Category("look")]
public DateTime [] MyDates
{
get { return theDate;}
set {theDate = value;}
}

When I add my control to the form I can open the DateTime collection editor
from the properties window and set certain dates, but they do not seem to
show on my control, whereas creating an array of DateTimes in code works
fine. In fact, when I go back into the DateTime editor after running the
program, the list only contains one entry, despite having entered 6
previously.

Does anyone know a way round this?
Aug 3 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

If you are referring to a web control, then none of the values you enter in the collection editor should be preserved since
DateTime[] cannot be automatically converted to and from a string representation. For that you'd have to create a custom
TypeConverter.

I tested your claim in a WinForms 2.0 app. All of the dates that I added in the collection editor to the DateTime[] property were
preserved at runtime. I cannot reproduce the behavior you have specified.

Here's the bulk of my control class:

public DateTime[] MyDates
{
get { return dates; }
set
{
dates = value;
Invalidate();
}
}

private DateTime[] dates;

protected override void OnPaint(PaintEventArgs pe)
{
if (dates == null)
pe.Graphics.DrawString("Null", Font, Brushes.Black, 0, 0);
else
{
int fontHeight = Font.Height;
int y = 0;

foreach (DateTime dt in dates)
{
pe.Graphics.DrawString(dt.ToString(), Font, Brushes.Black, 0, y);

y += fontHeight + 2;
}
}

// Calling the base class OnPaint
base.OnPaint(pe);
}

Is there anything in particular that I'm missing?

--
Dave Sexton

"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message news:9B**********************************@microsof t.com...
>I have created a control and added a few properties. One of these is an
array of DateTime objects, looking like this:

[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
Description("whatever"), Category("look")]
public DateTime [] MyDates
{
get { return theDate;}
set {theDate = value;}
}

When I add my control to the form I can open the DateTime collection editor
from the properties window and set certain dates, but they do not seem to
show on my control, whereas creating an array of DateTimes in code works
fine. In fact, when I go back into the DateTime editor after running the
program, the list only contains one entry, despite having entered 6
previously.

Does anyone know a way round this?

Aug 6 '06 #2

P: n/a
Hi Dave,

many thanks for replying.

I am creating a Windows application using Visual Studio .NET 2003, so I
don't know how valid this information will be. I don't see how the paint
handler will affect the properties window at design time. I have since
entered a few more dates, closed the dialog, then opened it again. None of
the dates I entered were still visible.

I think there must be a simple way to create a collection property in a
Windows application and make it available in the properties window.

Thanks again, Dave,

Mac

"Dave Sexton" wrote:
Hi,

If you are referring to a web control, then none of the values you enter in the collection editor should be preserved since
DateTime[] cannot be automatically converted to and from a string representation. For that you'd have to create a custom
TypeConverter.

I tested your claim in a WinForms 2.0 app. All of the dates that I added in the collection editor to the DateTime[] property were
preserved at runtime. I cannot reproduce the behavior you have specified.

Here's the bulk of my control class:

public DateTime[] MyDates
{
get { return dates; }
set
{
dates = value;
Invalidate();
}
}

private DateTime[] dates;

protected override void OnPaint(PaintEventArgs pe)
{
if (dates == null)
pe.Graphics.DrawString("Null", Font, Brushes.Black, 0, 0);
else
{
int fontHeight = Font.Height;
int y = 0;

foreach (DateTime dt in dates)
{
pe.Graphics.DrawString(dt.ToString(), Font, Brushes.Black, 0, y);

y += fontHeight + 2;
}
}

// Calling the base class OnPaint
base.OnPaint(pe);
}

Is there anything in particular that I'm missing?

--
Dave Sexton

"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message news:9B**********************************@microsof t.com...
I have created a control and added a few properties. One of these is an
array of DateTime objects, looking like this:

[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
Description("whatever"), Category("look")]
public DateTime [] MyDates
{
get { return theDate;}
set {theDate = value;}
}

When I add my control to the form I can open the DateTime collection editor
from the properties window and set certain dates, but they do not seem to
show on my control, whereas creating an array of DateTimes in code works
fine. In fact, when I go back into the DateTime editor after running the
program, the list only contains one entry, despite having entered 6
previously.

Does anyone know a way round this?


Aug 7 '06 #3

P: n/a
Hi Mac,
I am creating a Windows application using Visual Studio .NET 2003, so I
don't know how valid this information will be.
I tested the code in VS.NET 2003 as well and I was able to repro the described behavior. By simply initializing the 'dates' field
to a non-null value I was able to get the desired behavior. Apparently they fixed this behavior in VS.NET 2005 so that a collection
is still handled properly by the designer when it's initialized to null in the class.

public DateTime[] MyDates
{
get { return dates; }
set
{
dates = value;
Invalidate();
}
}

// field must be initialized to a non-null value
private DateTime[] dates = new DateTime[0];
I don't see how the paint
handler will affect the properties window at design time.
It won't. The purpose of painting was to display the dates that are part of the collection at design-time so I wouldn't have to
keep building and running the app.
I have since
entered a few more dates, closed the dialog, then opened it again. None of
the dates I entered were still visible.
I think there must be a simple way to create a collection property in a
Windows application and make it available in the properties window.
This is the simplest way that I'm aware of, and it's pretty simple, IMO. You might want to post your code if my suggestion doesn't
work for you.

--
Dave Sexton

"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message news:27**********************************@microsof t.com...
Hi Dave,

many thanks for replying.

I am creating a Windows application using Visual Studio .NET 2003, so I
don't know how valid this information will be. I don't see how the paint
handler will affect the properties window at design time. I have since
entered a few more dates, closed the dialog, then opened it again. None of
the dates I entered were still visible.

I think there must be a simple way to create a collection property in a
Windows application and make it available in the properties window.

Thanks again, Dave,

Mac

"Dave Sexton" wrote:
>Hi,

If you are referring to a web control, then none of the values you enter in the collection editor should be preserved since
DateTime[] cannot be automatically converted to and from a string representation. For that you'd have to create a custom
TypeConverter.

I tested your claim in a WinForms 2.0 app. All of the dates that I added in the collection editor to the DateTime[] property
were
preserved at runtime. I cannot reproduce the behavior you have specified.

Here's the bulk of my control class:

public DateTime[] MyDates
{
get { return dates; }
set
{
dates = value;
Invalidate();
}
}

private DateTime[] dates;

protected override void OnPaint(PaintEventArgs pe)
{
if (dates == null)
pe.Graphics.DrawString("Null", Font, Brushes.Black, 0, 0);
else
{
int fontHeight = Font.Height;
int y = 0;

foreach (DateTime dt in dates)
{
pe.Graphics.DrawString(dt.ToString(), Font, Brushes.Black, 0, y);

y += fontHeight + 2;
}
}

// Calling the base class OnPaint
base.OnPaint(pe);
}

Is there anything in particular that I'm missing?

--
Dave Sexton

"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message news:9B**********************************@microsof t.com...
>I have created a control and added a few properties. One of these is an
array of DateTime objects, looking like this:

[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
Description("whatever"), Category("look")]
public DateTime [] MyDates
{
get { return theDate;}
set {theDate = value;}
}

When I add my control to the form I can open the DateTime collection editor
from the properties window and set certain dates, but they do not seem to
show on my control, whereas creating an array of DateTimes in code works
fine. In fact, when I go back into the DateTime editor after running the
program, the list only contains one entry, despite having entered 6
previously.

Does anyone know a way round this?



Aug 7 '06 #4

P: n/a
Thanks again, Dave.

I will have a play with that.

"Dave Sexton" wrote:
Hi Mac,
I am creating a Windows application using Visual Studio .NET 2003, so I
don't know how valid this information will be.

I tested the code in VS.NET 2003 as well and I was able to repro the described behavior. By simply initializing the 'dates' field
to a non-null value I was able to get the desired behavior. Apparently they fixed this behavior in VS.NET 2005 so that a collection
is still handled properly by the designer when it's initialized to null in the class.

public DateTime[] MyDates
{
get { return dates; }
set
{
dates = value;
Invalidate();
}
}

// field must be initialized to a non-null value
private DateTime[] dates = new DateTime[0];
I don't see how the paint
handler will affect the properties window at design time.

It won't. The purpose of painting was to display the dates that are part of the collection at design-time so I wouldn't have to
keep building and running the app.
I have since
entered a few more dates, closed the dialog, then opened it again. None of
the dates I entered were still visible.
I think there must be a simple way to create a collection property in a
Windows application and make it available in the properties window.

This is the simplest way that I'm aware of, and it's pretty simple, IMO. You might want to post your code if my suggestion doesn't
work for you.

--
Dave Sexton

"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message news:27**********************************@microsof t.com...
Hi Dave,

many thanks for replying.

I am creating a Windows application using Visual Studio .NET 2003, so I
don't know how valid this information will be. I don't see how the paint
handler will affect the properties window at design time. I have since
entered a few more dates, closed the dialog, then opened it again. None of
the dates I entered were still visible.

I think there must be a simple way to create a collection property in a
Windows application and make it available in the properties window.

Thanks again, Dave,

Mac

"Dave Sexton" wrote:
Hi,

If you are referring to a web control, then none of the values you enter in the collection editor should be preserved since
DateTime[] cannot be automatically converted to and from a string representation. For that you'd have to create a custom
TypeConverter.

I tested your claim in a WinForms 2.0 app. All of the dates that I added in the collection editor to the DateTime[] property
were
preserved at runtime. I cannot reproduce the behavior you have specified.

Here's the bulk of my control class:

public DateTime[] MyDates
{
get { return dates; }
set
{
dates = value;
Invalidate();
}
}

private DateTime[] dates;

protected override void OnPaint(PaintEventArgs pe)
{
if (dates == null)
pe.Graphics.DrawString("Null", Font, Brushes.Black, 0, 0);
else
{
int fontHeight = Font.Height;
int y = 0;

foreach (DateTime dt in dates)
{
pe.Graphics.DrawString(dt.ToString(), Font, Brushes.Black, 0, y);

y += fontHeight + 2;
}
}

// Calling the base class OnPaint
base.OnPaint(pe);
}

Is there anything in particular that I'm missing?

--
Dave Sexton

"cashdeskmac" <ca*********@discussions.microsoft.comwrote in message news:9B**********************************@microsof t.com...
I have created a control and added a few properties. One of these is an
array of DateTime objects, looking like this:

[Browsable(true), EditorBrowsable(EditorBrowsableState.Always),
Description("whatever"), Category("look")]
public DateTime [] MyDates
{
get { return theDate;}
set {theDate = value;}
}

When I add my control to the form I can open the DateTime collection editor
from the properties window and set certain dates, but they do not seem to
show on my control, whereas creating an array of DateTimes in code works
fine. In fact, when I go back into the DateTime editor after running the
program, the list only contains one entry, despite having entered 6
previously.

Does anyone know a way round this?


Aug 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.