D
DJB MASTER
Guest
Hi, how can i limit the amount of characters that can be entered into a property of a propertygrid? I'm trying to allow only 20 characters to be entered. I want it to stop entering characters rather than stripping the value to 20 after it has been entered.
I've managed to use UITypeEditor to create a textbox that limits the entry, but i can only show it with a drop-down. I want it to behave like a normal property field...
public class LimitTextEditor : UITypeEditor
{
public LimitTextEditor() {}
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
if (value.GetType() != typeof(string))
return value;
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
TextBox txt = new TextBox();
txt.Text = value.ToString();
txt.Size = new Size(200, 100);
txt.MaxLength = 20;
edSvc.DropDownControl(txt);
return txt.Text;
}
return value;
}
}
Thanks.
Continue reading...
I've managed to use UITypeEditor to create a textbox that limits the entry, but i can only show it with a drop-down. I want it to behave like a normal property field...
public class LimitTextEditor : UITypeEditor
{
public LimitTextEditor() {}
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
if (value.GetType() != typeof(string))
return value;
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
TextBox txt = new TextBox();
txt.Text = value.ToString();
txt.Size = new Size(200, 100);
txt.MaxLength = 20;
edSvc.DropDownControl(txt);
return txt.Text;
}
return value;
}
}
Thanks.
Continue reading...