nullptr for a property

  • Thread starter Thread starter --== Alain ==--
  • Start date Start date
A

--== Alain ==--

Hi,

I would like to define the default value of my property.
My property is from type Bitmap^, therefore i was thinking to do :

[DefaultValueAttribute(nullptr)]

but i does not work.
how is it possible to define this property to no pointer ?

thx.

ALain
 
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
...\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
thanks,

Al.
 
--== Alain ==-- said:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?

It's not necessary. If you simply don't assign a value to the property (or
the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the default
property of the class. It does not provide a default value for a property,
which is apparently what you're trying to do.

-cd
 
He might be trying to set the default value of the property if he is
planning on designing the class. It won't default the value when the
instance is created but it will allow the designer to reset the value of
the property and exclude the redundant value when the instance is
serialized to xml or codedom.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com




--== Alain ==-- said:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?


It's not necessary. If you simply don't assign a value to the property (or
the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the default
property of the class. It does not provide a default value for a property,
which is apparently what you're trying to do.

-cd
 
Thanks Carl, but i went to this direction according to my other issue...

when i assigned a bitmap to this property, it's ok and everything works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property editor
and press delete key...
it clear the property field value and it should display (none) as usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap,
but never clear the field :-(

do you have an idea ?

thx.

Al.
--== Alain ==-- said:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?

It's not necessary. If you simply don't assign a value to the property (or
the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the default
property of the class. It does not provide a default value for a property,
which is apparently what you're trying to do.

-cd
 
You could try the
DefaultValueAttribute instead...

--== Alain ==-- said:
Thanks Carl, but i went to this direction according to my other issue...

when i assigned a bitmap to this property, it's ok and everything works.
However, once a bitmap is assigned, and i want to delete this assignment,
i usually use select the property value in property editor and press
delete key...
it clear the property field value and it should display (none) as usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap, but
never clear the field :-(

do you have an idea ?

thx.

Al.
--== Alain ==-- said:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?

It's not necessary. If you simply don't assign a value to the property
(or the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the default
property of the class. It does not provide a default value for a
property, which is apparently what you're trying to do.

-cd
 
My problem is not to assign a value to this property. I think it it how
to clear it, if user press DELETE, BACKSPACE keys when this property has
the focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage
property, just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd said:
You could try the
DefaultValueAttribute instead...

--== Alain ==-- said:
Thanks Carl, but i went to this direction according to my other issue...

when i assigned a bitmap to this property, it's ok and everything works.
However, once a bitmap is assigned, and i want to delete this assignment,
i usually use select the property value in property editor and press
delete key...
it clear the property field value and it should display (none) as usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap, but
never clear the field :-(

do you have an idea ?

thx.

Al.
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the property
(or the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the default
property of the class. It does not provide a default value for a
property, which is apparently what you're trying to do.

-cd
 
Well why don't you try the "DefaultValueAttribute" as I told you?
I think it's exactky what you need!


Anyway, FYI, here is what reflector says about Control.BackgroundImage:
[System::ComponentModel::DefaultValue(*static_cast<__box
System::String*>(0)), System::ComponentModel::Localizable(true),
System::Windows::Forms::SRDescription(S"ControlBackgroundImageDescr"),
System::Windows::Forms::SRCategory(S"CatAppearance")]
public: __property virtual System::Drawing::Image __gc*
get_BackgroundImage()
{
return *static_cast<__box
System::Drawing::Image*>(this->Properties->GetObject(System::Windows::Forms::Control::PropBackgroundImage));
}public: __property virtual void __gc*
set_BackgroundImage(System::Drawing::Image __gc* value)
{
if (this->BackgroundImage != value)
{
this->Properties->SetObject(System::Windows::Forms::Control::PropBackgroundImage,
value);
this->OnBackgroundImageChanged(System::EventArgs::Empty);
}
}



--== Alain ==-- said:
My problem is not to assign a value to this property. I think it it how to
clear it, if user press DELETE, BACKSPACE keys when this property has the
focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage property,
just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd said:
You could try the
DefaultValueAttribute instead...

--== Alain ==-- said:
Thanks Carl, but i went to this direction according to my other issue...

when i assigned a bitmap to this property, it's ok and everything works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property editor
and press delete key...
it clear the property field value and it should display (none) as
usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap,
but never clear the field :-(

do you have an idea ?

thx.

Al.

Carl Daniel [VC++ MVP] wrote:
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the property
(or the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the
default property of the class. It does not provide a default value for
a property, which is apparently what you're trying to do.

-cd
 
i tried but it does not work as expected :-(
when i see the code you wrote, it seems that an event is also added.
is it like that for all properties ? because i've not seen it till now.

moreover, where did you find the code below ? in help ?
i did not find it..

thx.
Al.

Lloyd said:
Well why don't you try the "DefaultValueAttribute" as I told you?
I think it's exactky what you need!


Anyway, FYI, here is what reflector says about Control.BackgroundImage:
[System::ComponentModel::DefaultValue(*static_cast<__box
System::String*>(0)), System::ComponentModel::Localizable(true),
System::Windows::Forms::SRDescription(S"ControlBackgroundImageDescr"),
System::Windows::Forms::SRCategory(S"CatAppearance")]
public: __property virtual System::Drawing::Image __gc*
get_BackgroundImage()
{
return *static_cast<__box
System::Drawing::Image*>(this->Properties->GetObject(System::Windows::Forms::Control::PropBackgroundImage));
}public: __property virtual void __gc*
set_BackgroundImage(System::Drawing::Image __gc* value)
{
if (this->BackgroundImage != value)
{
this->Properties->SetObject(System::Windows::Forms::Control::PropBackgroundImage,
value);
this->OnBackgroundImageChanged(System::EventArgs::Empty);
}
}



--== Alain ==-- said:
My problem is not to assign a value to this property. I think it it how to
clear it, if user press DELETE, BACKSPACE keys when this property has the
focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage property,
just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd said:
You could try the
DefaultValueAttribute instead...

Thanks Carl, but i went to this direction according to my other issue...

when i assigned a bitmap to this property, it's ok and everything works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property editor
and press delete key...
it clear the property field value and it should display (none) as
usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap,
but never clear the field :-(

do you have an idea ?

thx.

Al.

Carl Daniel [VC++ MVP] wrote:
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the property
(or the private field that backs it up), then it WILL be null.

The DefaultProperty attribute is applied to a class and names the
default property of the class. It does not provide a default value for
a property, which is apparently what you're trying to do.

-cd
 
Google: Must have .NET developer tools
=> http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/

Google: Reflector .NET
=> http://www.aisto.com/roeder/dotnet/

Reflector is the tool which will give you the source code from an MSIL.


--== Alain ==-- said:
i tried but it does not work as expected :-(
when i see the code you wrote, it seems that an event is also added.
is it like that for all properties ? because i've not seen it till now.

moreover, where did you find the code below ? in help ?
i did not find it..

thx.
Al.

Lloyd said:
Well why don't you try the "DefaultValueAttribute" as I told you?
I think it's exactky what you need!


Anyway, FYI, here is what reflector says about Control.BackgroundImage:
[System::ComponentModel::DefaultValue(*static_cast<__box
System::String*>(0)), System::ComponentModel::Localizable(true),
System::Windows::Forms::SRDescription(S"ControlBackgroundImageDescr"),
System::Windows::Forms::SRCategory(S"CatAppearance")]
public: __property virtual System::Drawing::Image __gc*
get_BackgroundImage()
{
return *static_cast<__box
System::Drawing::Image*>(this->Properties->GetObject(System::Windows::Forms::Control::PropBackgroundImage));
}public: __property virtual void __gc*
set_BackgroundImage(System::Drawing::Image __gc* value)
{
if (this->BackgroundImage != value)
{

this->Properties->SetObject(System::Windows::Forms::Control::PropBackgroundImage,
value);
this->OnBackgroundImageChanged(System::EventArgs::Empty);
}
}



--== Alain ==-- said:
My problem is not to assign a value to this property. I think it it how
to clear it, if user press DELETE, BACKSPACE keys when this property has
the focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage
property, just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd Dupont wrote:
You could try the
DefaultValueAttribute instead...

Thanks Carl, but i went to this direction according to my other
issue...

when i assigned a bitmap to this property, it's ok and everything
works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property editor
and press delete key...
it clear the property field value and it should display (none) as
usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap,
but never clear the field :-(

do you have an idea ?

thx.

Al.

Carl Daniel [VC++ MVP] wrote:
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute
is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the
property (or the private field that backs it up), then it WILL be
null.

The DefaultProperty attribute is applied to a class and names the
default property of the class. It does not provide a default value
for a property, which is apparently what you're trying to do.

-cd
 
Thanks for information but after your previous post, i got it ;-)

however, i would like to understand something.
It seems that everything is written with CLI managed v1, while i use v2.
therefore, as i do not want to use v1, i do not have /clr:OldSyntax as
compiler option.

I tried to migrate the code from v1 to v2 of CLI managed, but without
success. I still have the same issue. I can not clear my property field
value by pressing DELETE or BACKSPACE keys.

Something must be wrong in my code :-( or i miss the point...

Al.

Lloyd said:
Google: Must have .NET developer tools
=> http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/

Google: Reflector .NET
=> http://www.aisto.com/roeder/dotnet/

Reflector is the tool which will give you the source code from an MSIL.


--== Alain ==-- said:
i tried but it does not work as expected :-(
when i see the code you wrote, it seems that an event is also added.
is it like that for all properties ? because i've not seen it till now.

moreover, where did you find the code below ? in help ?
i did not find it..

thx.
Al.

Lloyd said:
Well why don't you try the "DefaultValueAttribute" as I told you?
I think it's exactky what you need!


Anyway, FYI, here is what reflector says about Control.BackgroundImage:
[System::ComponentModel::DefaultValue(*static_cast<__box
System::String*>(0)), System::ComponentModel::Localizable(true),
System::Windows::Forms::SRDescription(S"ControlBackgroundImageDescr"),
System::Windows::Forms::SRCategory(S"CatAppearance")]
public: __property virtual System::Drawing::Image __gc*
get_BackgroundImage()
{
return *static_cast<__box
System::Drawing::Image*>(this->Properties->GetObject(System::Windows::Forms::Control::PropBackgroundImage));
}public: __property virtual void __gc*
set_BackgroundImage(System::Drawing::Image __gc* value)
{
if (this->BackgroundImage != value)
{

this->Properties->SetObject(System::Windows::Forms::Control::PropBackgroundImage,
value);
this->OnBackgroundImageChanged(System::EventArgs::Empty);
}
}



My problem is not to assign a value to this property. I think it it how
to clear it, if user press DELETE, BACKSPACE keys when this property has
the focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage
property, just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd Dupont wrote:
You could try the
DefaultValueAttribute instead...

Thanks Carl, but i went to this direction according to my other
issue...

when i assigned a bitmap to this property, it's ok and everything
works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property editor
and press delete key...
it clear the property field value and it should display (none) as
usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap,
but never clear the field :-(

do you have an idea ?

thx.

Al.

Carl Daniel [VC++ MVP] wrote:
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute
is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the
property (or the private field that backs it up), then it WILL be
null.

The DefaultProperty attribute is applied to a class and names the
default property of the class. It does not provide a default value
for a property, which is apparently what you're trying to do.

-cd
 
I've found where was the problem... at least :-)

i should cast my default value to String as follow :
System::ComponentModel::DefaultValueAttribute(static_cast
<System::String^> (nullptr))]

and not to an image^ ... like that it allow DELETE and BACKSPACE keys to
be used.

thx a lot Lloyd !

Alain



Lloyd said:
Google: Must have .NET developer tools
=> http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/

Google: Reflector .NET
=> http://www.aisto.com/roeder/dotnet/

Reflector is the tool which will give you the source code from an MSIL.


--== Alain ==-- said:
i tried but it does not work as expected :-(
when i see the code you wrote, it seems that an event is also added.
is it like that for all properties ? because i've not seen it till now.

moreover, where did you find the code below ? in help ?
i did not find it..

thx.
Al.

Lloyd said:
Well why don't you try the "DefaultValueAttribute" as I told you?
I think it's exactky what you need!


Anyway, FYI, here is what reflector says about Control.BackgroundImage:
[System::ComponentModel::DefaultValue(*static_cast<__box
System::String*>(0)), System::ComponentModel::Localizable(true),
System::Windows::Forms::SRDescription(S"ControlBackgroundImageDescr"),
System::Windows::Forms::SRCategory(S"CatAppearance")]
public: __property virtual System::Drawing::Image __gc*
get_BackgroundImage()
{
return *static_cast<__box
System::Drawing::Image*>(this->Properties->GetObject(System::Windows::Forms::Control::PropBackgroundImage));
}public: __property virtual void __gc*
set_BackgroundImage(System::Drawing::Image __gc* value)
{
if (this->BackgroundImage != value)
{

this->Properties->SetObject(System::Windows::Forms::Control::PropBackgroundImage,
value);
this->OnBackgroundImageChanged(System::EventArgs::Empty);
}
}



My problem is not to assign a value to this property. I think it it how
to clear it, if user press DELETE, BACKSPACE keys when this property has
the focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage
property, just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd Dupont wrote:
You could try the
DefaultValueAttribute instead...

Thanks Carl, but i went to this direction according to my other
issue...

when i assigned a bitmap to this property, it's ok and everything
works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property editor
and press delete key...
it clear the property field value and it should display (none) as
usual...

but nothing happens... since i assign a bitmap, i can not have anymore
this property field value to (none). I can only assign another bitmap,
but never clear the field :-(

do you have an idea ?

thx.

Al.

Carl Daniel [VC++ MVP] wrote:
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute
is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the
property (or the private field that backs it up), then it WILL be
null.

The DefaultProperty attribute is applied to a class and names the
default property of the class. It does not provide a default value
for a property, which is apparently what you're trying to do.

-cd
 
Do not worry about the syntax!
It might very well have been written in C# to start with, it's just
reflector which decompile in old MC++ syntax!

Glad you solved your problem.

--== Alain ==-- said:
Thanks for information but after your previous post, i got it ;-)

however, i would like to understand something.
It seems that everything is written with CLI managed v1, while i use v2.
therefore, as i do not want to use v1, i do not have /clr:OldSyntax as
compiler option.

I tried to migrate the code from v1 to v2 of CLI managed, but without
success. I still have the same issue. I can not clear my property field
value by pressing DELETE or BACKSPACE keys.

Something must be wrong in my code :-( or i miss the point...

Al.

Lloyd said:
Google: Must have .NET developer tools
=> http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/

Google: Reflector .NET
=> http://www.aisto.com/roeder/dotnet/

Reflector is the tool which will give you the source code from an MSIL.


--== Alain ==-- said:
i tried but it does not work as expected :-(
when i see the code you wrote, it seems that an event is also added.
is it like that for all properties ? because i've not seen it till now.

moreover, where did you find the code below ? in help ?
i did not find it..

thx.
Al.

Lloyd Dupont wrote:
Well why don't you try the "DefaultValueAttribute" as I told you?
I think it's exactky what you need!


Anyway, FYI, here is what reflector says about Control.BackgroundImage:
[System::ComponentModel::DefaultValue(*static_cast<__box
System::String*>(0)), System::ComponentModel::Localizable(true),
System::Windows::Forms::SRDescription(S"ControlBackgroundImageDescr"),
System::Windows::Forms::SRCategory(S"CatAppearance")]
public: __property virtual System::Drawing::Image __gc*
get_BackgroundImage()
{
return *static_cast<__box
System::Drawing::Image*>(this->Properties->GetObject(System::Windows::Forms::Control::PropBackgroundImage));
}public: __property virtual void __gc*
set_BackgroundImage(System::Drawing::Image __gc* value)
{
if (this->BackgroundImage != value)
{

this->Properties->SetObject(System::Windows::Forms::Control::PropBackgroundImage,
value);
this->OnBackgroundImageChanged(System::EventArgs::Empty);
}
}



My problem is not to assign a value to this property. I think it it
how to clear it, if user press DELETE, BACKSPACE keys when this
property has the focus in the property editor.

For example if i assign a bitmap to form thanks backgroundimage
property, just by pressing delete, this property is cleared.
i would like to have the same for my property..

that's all

Al.

Lloyd Dupont wrote:
You could try the
DefaultValueAttribute instead...

Thanks Carl, but i went to this direction according to my other
issue...

when i assigned a bitmap to this property, it's ok and everything
works.
However, once a bitmap is assigned, and i want to delete this
assignment, i usually use select the property value in property
editor and press delete key...
it clear the property field value and it should display (none) as
usual...

but nothing happens... since i assign a bitmap, i can not have
anymore this property field value to (none). I can only assign
another bitmap, but never clear the field :-(

do you have an idea ?

thx.

Al.

Carl Daniel [VC++ MVP] wrote:
--== Alain ==-- wrote:
here is my code :

#pragma region public Property : ImageSortAscendant
// Allow user to select the image which will be displayed for
column
sorted ascendantly

[System::ComponentModel::DefaultPropertyAttribute (nullptr)]
property Bitmap^ ImageSortAscendant
{
Bitmap^ get()
{
return m_ImageSortA;
}
void set(System::Drawing::Bitmap^ value)
{
m_ImageSortA = value;
}
}
#pragma endregion

but when i try to compile, i have the following error :
..\RAF_ListView.h(177) : error C3115:
'System::ComponentModel::DefaultPropertyAttribute': this attribute
is
not allowed on 'RAF_ListView::AR_ListView::ImageSortAscendant'

how could it be possible ?
It's not necessary. If you simply don't assign a value to the
property (or the private field that backs it up), then it WILL be
null.

The DefaultProperty attribute is applied to a class and names the
default property of the class. It does not provide a default value
for a property, which is apparently what you're trying to do.

-cd
 
Back
Top