|
Infralution Support Support groups for Infralution products
|
View previous topic :: View next topic |
Author |
Message |
Mrdec
Joined: 04 May 2006 Posts: 7
|
Posted: Thu Jun 08, 2006 5:11 pm Post subject: Custom type editor |
|
|
Hello,
I need help with custom UITypeEditor. For demonstration of the problem I wrote following example. There are two columns Name and Value in my tree. The Value column is editable (by UniversalEditBox). I have my custom UITypeEditor named MyUITypeEditor (in this simple example it does nothing but shows only dropdown button).
I use programatic binding to MyObj objects. I would like to use my custom editor in case of MyObj.UseCombo property is equal to true, otherwise use default editor.
I expected that I could use in tree_GetCellData event handler this assignment:
Code: |
e.CellData.TypeEditor = myUITypeEditor;
|
But it sometimes works and sometimes doesn't. I attached animated gif to demonstrate it. Objects with values "A", "AA" have UseCombo=false and objects with values "B", "BB" have UseCombo=true. First time it works (A's have editbox B's have combobox, but I collapse and expand root node and all of them have combobox)
Could you help me, please?
Thanks, Mrdec
MyObj object used for binding
Code: |
public class MyObj
{
public string Name;
public string Value;
public bool UseCombo;
public List<MyObj> Children = new List<MyObj>();
public MyObj Parent;
public MyObj(MyObj parent, string name, string val, bool useCombo)
{
Parent = parent;
Name = name;
Value = val;
UseCombo = useCombo;
}
}
|
MyUITypeEditor custom UITypeEditor
Code: |
public class MyUITypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
}
|
MyForm main formr with VirtualTree (named tree) placed on it
Code: |
public partial class MyForm : Form
{
private Column colName = new Column();
private Column colValue = new Column();
private MyObj RootObj;
private MyUITypeEditor myUITypeEditor = new MyUITypeEditor();
private CellEditor cellEditor = new CellEditor();
private UniversalEditBox editBox = new UniversalEditBox();
public MyForm()
{
InitializeComponent();
// init tree
colName.Caption = "Name";
colValue.Caption = "Value";
tree.Columns.Add(colName);
tree.Columns.Add(colValue);
cellEditor.Control = editBox;
// init objects
RootObj = new MyObj(null, "Root", "", false);
RootObj.Children.Add(new MyObj(RootObj, "Child1", "A", false));
RootObj.Children.Add(new MyObj(RootObj, "Child2", "AA", false));
RootObj.Children.Add(new MyObj(RootObj, "Child3", "B", true));
RootObj.Children.Add(new MyObj(RootObj, "Child4", "BB", true));
tree.DataSource = RootObj;
}
private void tree_GetChildren(object sender, GetChildrenEventArgs e)
{
MyObj obj = (e.Row.Item as MyObj);
if (obj != null) e.Children = obj.Children;
}
private void tree_GetParent(object sender, GetParentEventArgs e)
{
MyObj obj = (e.Item as MyObj);
if (obj != null) e.Parent = obj.Parent;
}
private void tree_GetCellData(object sender, GetCellDataEventArgs e)
{
MyObj obj = (e.Row.Item as MyObj);
if (obj != null)
{
if (e.Column == colName) e.CellData.Value = obj.Name;
if (e.Column == colValue)
{
e.CellData.Value = obj.Value;
e.CellData.TypeEditor = obj.UseCombo ? myUITypeEditor : null;
e.CellData.Editor = cellEditor;
}
}
}
}
|
|
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jun 08, 2006 10:50 pm Post subject: |
|
|
If you can zip your sample project up and email it to support@infralution it will save us a bit of work and we will take a look at the issue. Just a thought - have you tried created separate Editors for each type of property and assigning these at the same time in GetCellData? _________________ Infralution Support |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Jun 09, 2006 2:04 pm Post subject: |
|
|
Thanks for the zipped project. I think the issue is related to the way the editor controls are cached and reused. This interacts with the way the UniversalEditBox handles when you set a null type editor. Anyway you can as I suggested in the last post fix the issue by simply creating a separate editor (and associated UniversalEditBox control) for each case eg
Code: | public partial class MyForm : Form
{
private Column colName = new Column();
private Column colValue = new Column();
private MyObj RootObj;
private MyUITypeEditor myUITypeEditor = new MyUITypeEditor();
private CellEditor cellEditor = new CellEditor();
private UniversalEditBox editBox = new UniversalEditBox();
private CellEditor cellEditor2 = new CellEditor();
private UniversalEditBox editBox2 = new UniversalEditBox();
public MyForm()
{
InitializeComponent();
// init tree
colName.Caption = "Name";
colValue.Caption = "Value";
tree.Columns.Add(colName);
tree.Columns.Add(colValue);
cellEditor.Control = editBox;
cellEditor2.Control = editBox2;
// init objects
RootObj = new MyObj(null, "Root", "", false);
RootObj.Children.Add(new MyObj(RootObj, "Child1", "A", false));
RootObj.Children.Add(new MyObj(RootObj, "Child2", "AA", false));
RootObj.Children.Add(new MyObj(RootObj, "Child3", "B", true));
RootObj.Children.Add(new MyObj(RootObj, "Child4", "BB", true));
tree.DataSource = RootObj;
}
private void tree_GetChildren(object sender, GetChildrenEventArgs e)
{
MyObj obj = (e.Row.Item as MyObj);
if (obj != null) e.Children = obj.Children;
}
private void tree_GetParent(object sender, GetParentEventArgs e)
{
MyObj obj = (e.Item as MyObj);
if (obj != null) e.Parent = obj.Parent;
}
private void tree_GetCellData(object sender, GetCellDataEventArgs e)
{
MyObj obj = (e.Row.Item as MyObj);
if (obj != null)
{
if (e.Column == colName) e.CellData.Value = obj.Name;
if (e.Column == colValue)
{
e.CellData.Value = obj.Value;
e.CellData.TypeEditor = obj.UseCombo ? myUITypeEditor : null;
e.CellData.Editor = obj.UseCombo ? cellEditor : cellEditor2; ;
}
}
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
Mrdec
Joined: 04 May 2006 Posts: 7
|
Posted: Fri Jun 09, 2006 2:36 pm Post subject: |
|
|
Thanks a lot. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|