Does anyone have an example or idea on embedding a user control within the cell (not drop down editor button) of a cell?
Currently I'm instantiating the usercontrol at runtime from class inheriting EmbeddableEditorBase, but I can't seem to get
the control to paint within the cell. I am also new to the Embeddable Editor archtecture so if anyone knows any good reference
sites that would be helpful. Thanks!
Creating your own editor is a very big task and probably requires several days, if not weeks, of coding - depending on the complexity of your editor and how familiar you are with the editors and how they work.If you intend to create your own editor, I recommend that you get a subscription to NetAdvantage that includes source code so you can use the existing editors as an example.
Generally, it's much easier to use or modify an existing editor to do what you need, rather than create a whole new editor on your own.
Oh... also, there's a sample of creating an editor. It's called the RichTextEmbeddableEditor sample. It's installed along with the rest of the NetAdvantage samples, which I think comes with the SDK now.
Thanks for the quick reply and suggestion! Going to review the sdk. I will let you know if that works out.
After going through the rtf sample (and some help from support) I found the solution. Basically the User Control has to be reparented and re-positioned in the OnBeforeEnterEditMode event. To make a long story short this done using the Controls.Add functionality. I did this in GetEmbeddableElement override.
owningControl.Controls.Add(myControl);
}
Basically the rtf sample can be retrofitted to support any type of control. Simply replace the RichTextBox instantiation with your own. This is can be a very meticulous process and you want to make sure your class structure matches exactly as the rtf sample.
Another snag I ran into was the the OnBeforeEnterEditMode didn't fire after adding the edit area to ChildElements (add function). This was because I was not forwarding my mousedown event from the UIElement (see InternalOnMouseDown if you experience this).
You will not need any of the rtf render logic so you can skip all that logic. But you will have to write your own render code
to display the graphics in the drawforeground override (*edit see other messages)
Hi,
Thanks so much its working fine ..
You might want to use the ResolveAppearance method on the cell so that you can get the properties that you need. If you only want the ForeColor, you could do:
AppearancePropFlags requestedProps = AppearancePropFlags.ForeColor;AppearanceData appearance = new AppearanceData();cell.ResolveAppearance(ref appearance, requestedProps);SolidBrush sbrush = new SolidBrush(appearance.ForeColor != Color.Empty ? appearance.ForeColor : Color.Black);
-Matt
You could check the row.activated/cell.activated properties and set the sbrush.color based on that value.
Thanks very much for the reply. Its working perfectly alright. But i need to change the font color at runtime. Since i'm using drawstring, i wont be able to do that at cell level (like cell.Appearance.Forecolor = Color.White) or row level.
Say for example, I have three columns "COL1", "COL2", "COL3" and three rows in the UltrawinGrid. I have my custom maked edit box control at "COL1" and the values forecolor will be Color.Black because i'm using the below mentioned line
Now, I have applied columnstyle property of "COL2" as ColumnStyle.Edit. So, whenever i click on "COL2" i need to change the fore color of "COL1" to white because i'm selecting the entire row (i.e, it should resembles like CellClickAction.Cellselect). But since i'm using DrawString, i wont be able to do that at cell level or row level. That is reason why i asked for rendering the masked edit box? or else it will be really helpful if anyother possible solution for this?
Thanks
Not sure on the masked edit box thing. But in the draw foreground override you can render your own graphics using the Graphics object and the drawstring method.
eg.
EmbeddableUIElement embeddableElement = embeddableUIElement;
SolidBrush sbrush = new SolidBrush(Color.Black);
format.Alignment = StringAlignment.Near;
sbrush,
embeddableElement.EditArea.X,
embeddableElement.EditArea.Y),
format);