Compact Framework 3.5 Set Form parent - winforms

In .net Compact Framework 2.0, you could add a form to another forms control array basically parenting the other form.
i.e._mainForm.Controls.Add(form);
This is not allowed in .net cf 3.5 and results in an exception:
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
at System.Windows.Forms.Control._SetParent(Control ctlParent)
at System.Windows.Forms.Control.set_Parent(Control value)
Is there a workaround or alternative for this? I need to be able to parent a form inside a panel on another form.

I think this contains answer to your question: http://207.46.16.248/en-us/netframework/bb986636.aspx
especially this part:
System.Windows.Forms.Form.Parent
Description
Forms can no longer be parented.
Previous Behavior
In .NET Compact Framework 1.0, forms could be parented to any other control
that supported child controls. In .NET Compact Framework 2.0, forms
could be parented to any other form.
New Behavior
In the .NET Compact
Framework version 3.5, forms cannot be parented.

You can use the following method to copy form controls to another form in .NET CF 3.5
// Clear old form controls
oldform.Controls.Clear();
// Copy controls from newform to oldform
foreach (Control ctl in newform.Controls)
{
oldform.Controls.Add(ctl);
}

Related

Calling winforms hosting Wpf grid cause error

I have a WinForms application that acts as a service(so no actual UI), but it is a WinForms application.
In this application I a form that has an ElementHost and in the elementHost I have a WPF grid.
In one of my classes I have this code:
Dim frm1 As New frmHostWpfGrid '->HERE I get the error
frm1.WpfGrid.WpfGridControl.BeginDataUpdate()
frm1.WpfGrid.WpfGridControl.ItemsSource = Nothing
frm1.WpfGrid.WpfGridControl.RestoreLayoutFromStream(LayoutStream)
frm1.WpfGrid.WpfGridControl.ItemsSource = mdtData
frm1.WpfGrid.WpfGridControl.EndDataUpdate()
THe error I get is:
The calling thread must be STA, because many UI components require this.
When I tried with a WinForms form and a grid I didn't have this problem.
PS1. Notice that I don't want to show the form
PS2. I tried to fill directly a WPF grid without a form and I got the same error
You are trying to create UI objects on a non UI thread. Its hard to tell exactly what is causing the error without seeing your form initialization code where it must be setting up some of the WPF elements.
I will need to know more about frmHostWpfGrid to give you an exact answer.

DevExpress theme to be set for windows controls

How could I set or change the style of windows default controls(Like button,textbox etc.) using the DevExpress themes/skins?
Application: Windows
Framework: .NET Framework 4.0
DevExpress WinForms Version: 14.2
Devexpress doesn't supports skinning of regular winforms controls. You need to use their own controls to get the application skinned/themed.
For TextBox you use TextEdit, for Button you use SimpleButton and so on.
But you can read the skin element colors at runtime and apply yourself.
Sample code from the above link(in case link rot in future):
DevExpress.Skins.Skin currentSkin;
DevExpress.Skins.SkinElement element;
string elementName;
currentSkin = DevExpress.Skins.CommonSkins.GetSkin(defaultLookAndFeel1.LookAndFeel);
elementName = DevExpress.Skins.CommonSkins.SkinTextBorder;
element = currentSkin[elementName];
Color skinBorderColor = element.Border.All;

How to find colletion of Forms?

i am developing an application in which there are many form i want to get a colletion of all these forms which are in open or hide state. how would i implement this.
This will help you get all forms opened by the application
FormCollection col = Application.OpenForms;
In .net 4.0 there is still a defect with Application.OpenForms. The form will be removed from the list of forms when changing ShowInTaskbar property. Use Application.OpenForms if you are sure that they do not change ShowInTaskbar. Otherwise think about managing your own OpenForms collection

Workaround for binding expression list on binding group being empty

In WPF 4 the binding expression list on the binding group, which is passed to the ValidationRule's Validate method, is empty.
It is the same whether AutoGenerateColumns is true or false, whether DataGridBoundColumns explicitly has been added to the datagrid.
In WPF 3.5 SP1 using the DataGrid from the Toolkit the binding expression list is filled with the excepted binding expressions (1 for each column in the data grid)
I consider this a bug and has posted it on the Microsoft Connect site:
https://connect.microsoft.com/WPF/feedback/details/642815/bindingexpressions-on-bindinggroup-passed-to-validationrule-in-datagrid-rowvalidationrules-is-empty
But does anyone have a workaround so I can get the correct binding expression from within the ValidationRule?
In order to support "proposed values" that are not committed to the target of a two-way binding until validation succeeds, the WPF 4.0 DataGrid was redesigned to take advantage of the the new BindingGroup.SharesProposedValues feature of WPF 4.0. Because of this change, it is no longer necessary to use two-way bindings in binding group of display templates.
You can use BindingGroup.TryGetValue to retrieve the proposed values for other columns instead of using the old method that worked with the DataGrid from the WPF Toolkit.
In other words, the new DataGrid actually fixes an undesirable feature of the old DataGrid and as a result things work slightly differently (i.e. the missing bindings are by design) but you can still do what you need to do.
The explanation in Microsoft's own words is in this Microsoft Connect link:
BindingExpressions on BindingGroup passed to ValidationRule in DataGrid.RowValidationRules is empty
And here is a blog that describes BindingGroup.SharesProposedValues in another way:
List of features to track in WPF4 and the details on beta1

Editing business objects in Winforms DataGridView

Is possible to edit properties of business object (one property, one column) binded as BindingList to Winforms DataGridView?
Or do I have to use DataSet or DataTable?
I'm not able to get a cell to edit mode.
Yes it is possible check out BindingList.
Otherwise the book Data Binding in Windows Forms 2.0 by Brian Noyes is an excellent reference book CH9 deals specifically with Binding Custom Business Objects.

Resources