Hi I am creating a control with a custom UITypeEditor in VS2010 .net 4.0 which works fine until I add it to a template in for example a repeater at which point I loose the elipsis button. As a test I then created a simple editor that doesn't do anything:
Because you only use your own class inheriting from TestEditor and return a Modal dialog for the user to continue his program as input things...
And if you want to do a self-made editor as an interface, you should apply it onto a class or very complicated object instead of on a single string... Something like this:
[Editor(typeof(GradeEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Grade
{
int score;
public int Score
{
get { return score; }
set { score = value; }
}
}
Here's a sample showing you how to define your own editor with UITypeEditor:
You can provide a small graphical representation along with the property value in the PropertyGrid, similar to what is provided for the Image and Color classes. To do this for your customization, inherit from UITypeEditor, override GetPaintValueSupported
and return true. Next, override the UITypeEditor.PaintValue method, and in your method, use the PaintValueEventArgs.Graphics parameter to draw your graphic. Finally, apply the Editor attribute to the class or property that uses your UITypeEditor class.
Bitmap b = new Bitmap(bumScore);
e.Graphics.DrawImage(b, e.Bounds);
b.Dispose();
}
//The following code uses the IServiceProvider passed to EditValue.
//It asks it for the IWindowsFormsEditorService interface
//(which is defined in the System.Windows.Forms.Design namespace).
//This service provides the facility for opening a drop-down editor,
//we simply call the DropDownControl method on it, and it will open whichever control we pass.
//It sets the size and location of the control
//so that it appears directly below the property when the drop-down arrow is clicked.
//When we write the UI editor class itself, we have a choice as to the kind of user interface we can supply.
//We can either open a modal dialog or supply a pop-up user interface
//that will appear in the property grid itself. We indicate this by overriding the GetEditStyle method.
//This method returns a value from the UITypeEditorEditStyle enumeration, either Modal or DropDown.
//For either type of user interface, we must also override the EditValue method,
//which will be called when the user tries to edit the value.
//The value returned from EditValue will be written back to the property.
//It will call EditValue when the arrow button is clicked.
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService wfes = provider.GetService(typeof(IWindowsFormsEditorService))
as IWindowsFormsEditorService;
if (wfes != null)
{
UserControl1 us = new UserControl1();
[Editor(typeof(GradeEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Grade
{
int score;
public int Score
{
get { return score; }
set { score = value; }
}
}
public class Test
{
Grade grade = new Grade();
public Grade Grade
{
get { return grade; }
set { grade = value; }
}
}
4、UserControl
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public IWindowsFormsEditorService _wfes;
public int BarValue;
Hi, I have just returned to this project after quite some time, I don't think you understood my issue. I have a working UITypeEditor in my control and all is fine until I try to use the control in a repeater template at which point the ellipsis button in
the property grid disappears. I don't get any errors and can't understand why this might happen?
JSP8
0 Points
2 Posts
UITypeEditor and ITemplate issue... Please help
Nov 07, 2011 01:40 PM|LINK
Hi I am creating a control with a custom UITypeEditor in VS2010 .net 4.0 which works fine until I add it to a template in for example a repeater at which point I loose the elipsis button. As a test I then created a simple editor that doesn't do anything:
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class TestEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
}
And a property on a control:
[Editor(typeof(TestEditor), typeof(UITypeEditor)), Bindable(false)]
public string Test { get; set; }
And I see the same behaviour, any help would be greatly appreciated...
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: UITypeEditor and ITemplate issue... Please help
Nov 09, 2011 12:59 AM|LINK
Hello sir:)
Because you only use your own class inheriting from TestEditor and return a Modal dialog for the user to continue his program as input things...
And if you want to do a self-made editor as an interface, you should apply it onto a class or very complicated object instead of on a single string... Something like this:
[Editor(typeof(GradeEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Grade
{
int score;
public int Score
{
get { return score; }
set { score = value; }
}
}
Here's a sample showing you how to define your own editor with UITypeEditor:
You can provide a small graphical representation along with the property value in the PropertyGrid, similar to what is provided for the Image and Color classes. To do this for your customization, inherit from UITypeEditor, override GetPaintValueSupported and return true. Next, override the UITypeEditor.PaintValue method, and in your method, use the PaintValueEventArgs.Graphics parameter to draw your graphic. Finally, apply the Editor attribute to the class or property that uses your UITypeEditor class.
From:http://msdn.microsoft.com/en-us/library/aa302326.aspx
public class GradeEditor : UITypeEditor
{
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
string bumScore = null;
Grade g = (Grade)e.Value;
if (g.Score > 90)
{
bumScore = @"E:\Personal\msPropertyGridStudy\msPropertyGridStudy\90.bmp";
}
else if (g.Score > 80 && g.Score < 90)
{
bumScore = @"E:\Personal\msPropertyGridStudy\msPropertyGridStudy\80.bmp";
}
else
{
bumScore = @"E:\Personal\msPropertyGridStudy\msPropertyGridStudy\70.bmp";
}
Bitmap b = new Bitmap(bumScore);
e.Graphics.DrawImage(b, e.Bounds);
b.Dispose();
}
//The following code uses the IServiceProvider passed to EditValue.
//It asks it for the IWindowsFormsEditorService interface
//(which is defined in the System.Windows.Forms.Design namespace).
//This service provides the facility for opening a drop-down editor,
//we simply call the DropDownControl method on it, and it will open whichever control we pass.
//It sets the size and location of the control
//so that it appears directly below the property when the drop-down arrow is clicked.
//When we write the UI editor class itself, we have a choice as to the kind of user interface we can supply.
//We can either open a modal dialog or supply a pop-up user interface
//that will appear in the property grid itself. We indicate this by overriding the GetEditStyle method.
//This method returns a value from the UITypeEditorEditStyle enumeration, either Modal or DropDown.
//For either type of user interface, we must also override the EditValue method,
//which will be called when the user tries to edit the value.
//The value returned from EditValue will be written back to the property.
//It will call EditValue when the arrow button is clicked.
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService wfes = provider.GetService(typeof(IWindowsFormsEditorService))
as IWindowsFormsEditorService;
if (wfes != null)
{
UserControl1 us = new UserControl1();
Grade g = (Grade)value;
us.trackBar1.Value = (int)g.Score / 10;
us.BarValue = us.trackBar1.Value;
us._wfes = wfes;
wfes.DropDownControl(us);
g.Score = us.BarValue;
}
return value;
}
}
[Editor(typeof(GradeEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Grade
{
int score;
public int Score
{
get { return score; }
set { score = value; }
}
}
public class Test
{
Grade grade = new Grade();
public Grade Grade
{
get { return grade; }
set { grade = value; }
}
}
4、UserControl
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public IWindowsFormsEditorService _wfes;
public int BarValue;
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
BarValue = trackBar1.Value * 10;
}
}
JSP8
0 Points
2 Posts
Re: UITypeEditor and ITemplate issue... Please help
Jan 04, 2013 11:14 PM|LINK
Hi, I have just returned to this project after quite some time, I don't think you understood my issue. I have a working UITypeEditor in my control and all is fine until I try to use the control in a repeater template at which point the ellipsis button in the property grid disappears. I don't get any errors and can't understand why this might happen?