473,241 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Custom properties

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
4 1476
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
0
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
0
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a...
0
by: Giorgio | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older...
8
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
4
by: Suresh | last post by:
Is there any way to access the custom properties of a master page from the aspx form? I know the custom properties of a master page can be accessed from the aspx.cs partial class by specifying...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.