473,406 Members | 2,867 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,406 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 1482
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.