I have a DataGrid
with a List<Foo>
as the datasource. I want the datagrid to use my custom control as the editor for the Foo.Value
property. I believe is the purpose of the UIHintAttribute, but it has no effect. I know I can explicitly make columns, and assign ValueColumn.ColumnEdit = new FooValueEditor();
, but I'm trying to side step what would be a lot of UI code and depend on the grid inferring columns from public properties.
class Foo
{
public string Name { get; set; }
[UIHint("FooValueEditor", "WinForms")]
public int Value { get; set; }
}
public class FooValueEditor : System.Windows.Forms.TextBox
{
public FooValueEditor() : base()
{
...
}
}
I've tried providing the full namespace to my custom editor. I find many examples of the attribute used in Asp.NET, but the attribute constructor takes a presentationLayer
parameter which:
Can be set to "HTML", "Silverlight", "WPF", or "WinForms".
I hope it supports WinForms. Am I doing something wrong? Is this not possible?
Edit:
Regarding comment "What is a DataGrid here". I am using a set of third party controls which I incorrectly assumed inherited from DataGrid. It supports the validation attributes (This is their documentation for Aps.Net, but it seems at least partly currect for WinForms also) in the same namespace so I was hopeful UIHint
might be supported. Looks like I should open a ticket directly with the third party provider, but in the mean time, the answer below will help me implement this myself if I choose to.