Click here to Skip to main content
14,733,037 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I am trying to create dynamic XamDataGrid with specific FieldLayOuts. I am doing it as Following.

//UnBound Field
UnboundField unBoundField = new UnboundField();
unBoundField.Label = "WFA";
Style stl = (Style)FindResource("UnBundcellStyle");
FieldSettings fieldSetting = new FieldSettings();
fieldSetting.CellValuePresenterStyle = stl;
unBoundField.Settings = fieldSetting;

//Regular Fieldse
Label lbl1 = new Label();
lbl1.Content = "Last Name";
Field field1 = new Field("LastName", lbl1);

Label lbl2 = new Label();
lbl2.Content = "First Name";
Field field2 = new Field("FirstName", lbl2);

Field field3 = new Field("IsEmployee");
field3.Visibility = Visibility.Collapsed;

FieldLayout fieldLayout = new FieldLayout();

XamDataGrid TechGrid = new XamDataGrid();

While doing this, I get an error " specified element is already the logical child of another element. disconnect it first."

What am I doing it wrong.?

[Modified: added pre tags]
Updated 22-Apr-10 13:15pm

Sorry, I am new here donno how to reply to individual Remarks,

But the problem is, while debugging everything seems to be looking good.
I don't get any error while going thru the above code. But before opening the window I get the error.
There can be few things possible:
1. You are trying to add a field again, may be to fieldLayout or to TechGrid.
2. Try specifying an ID to all fields, to avoid confusions.
3. You have already added a fieldLayout to TechGrid.

If this doesn't solve your problem then post the Exception details, or line number, we would be more than happy to help you.
At whatever line you get the error, you're trying to add something that is already added somewhere, what line gives the error ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900