I am trying to align the column headers for my XamDataGrid which is bound to DataSet (with multiple DataTable parent-child relationship).
Attached is the sample project files (Cannot upload the whole solution here). We are using 16.1.20161.1000 version of IG WPF.
Can you please suggest where am I going wrong ?
I have been looking into your question and found this forum thread where a similar question has been discussed. According to the suggestion, XamDataGrid header label could be aligned in:
<igDP:FieldSettings LabelTextAlignment="Center" />
this.myGrid.FieldLayouts.Fields.Settings.LabelTextAlignment = TextAlignment.Center;
Please have a look at it and if this is not an accurate demonstration of what you are trying to achieve you can provide your own sample by removing any external dependencies and code that is not directly related to the issue, zip your application and attach it in this case. If it still could not be attached you can upload it in a cloud by your choice and share a link to it.
Looking forward to hearing from you.
Sincerely, Teodosia Hristodorova Associate Software Developer
Here is my project link --> https://drive.google.com/open?id=16QA64FJruqVYjM8DpkJ9HgmWcrafXzVD.
Kindly advise at the earliest.
Thank you for the provided sample application. It helped me a lot.
After looking further into it, I determined that the reason for the described behavior is that the field width property is set to “auto”. This means that the column width would be calculated based on the content of the column cells at each level. Because of that, there would be differences in the alignment of the columns between the levels. In order for the columns on each level to be aligned I removed
field.Width = FieldLength.Auto;
An anlternative approach, if you want to keep the width to “auto”, would be to keep the children's labels. This way the columns would not be aligned, however, the data would be displayed in an understandable manner. In order to achieve that you can remove
e.FieldLayout.Settings.LabelLocation = LabelLocation.Hidden;
I modified the attached sample by removing the auto field width. Additionally in the project folder could be found a screenshot (Grid_Behavior.png) with the different grid appearance in both cases.
Please let me know if you need any further assistance with this matter.
Thanks for helping out. I see the sample that you gave.
I dont like the 1st image that you gave. This whole thing happened because initially I was using XamTreeGrid and it was working out wonderful but the problem with it is that it does not respect grouping at all (plz correct me if I am wrong). So, 1st image looks pretty ugly for my use case. Now, I set the FieldWidth to be auto because there can be many columns. My ideal scenario would be -->
1) For the Default layout, the Field.Width is set to Auto.
2) And the child layouts respect that and align accordingly when rendering. Same should be the case when I group by a particular field (e.g. by Action column).
Is the above requirement achievable ? Kindly let me know and if possible, kindly give me a sample.
My suggestion to achieve your requirement is first in the FieldLayoutInitialized event handler to set only the parent's fields Width property to Auto. In order to get this width and set it to the children fields width in the InitializeRecord event handler (which fires after the FieldLayoutInitialized), I'm using CellWidthResolved property. It's value is the actual width of cell because the value of the Width property is Auto, so if we try to get the parent Width value from there it will be Auto.
private void XamDataGrid1_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
if (e.Record.FieldLayout.Key.ToString() == "ChildOrders")
foreach(var cell in ((Infragistics.Windows.DataPresenter.DataRecord)e.Record).Cells)
cell.DataPresenter.MinWidth = 0;
cell.Field.Width = new FieldLength(((Infragistics.Windows.DataPresenter.ExpandableFieldRecord)e.Record.ParentRecord).Field.Owner.Fields[cell.Field.Index].CellWidthResolved);
I modified the previous sample and attached it below. Please test it on your side and let me know if I may be of any further assistance.
Associate Software Developer
This does help however if I try to increase the width of column manually, only the top layout field change. I would like the field widths of both layouts to be in sync.
Can you please let me know how this can be achieved.
Thanks in advance.
After doing some research I found that when a field is resized it will fire the SizeChanged event. However, there is no built-in functionality to achieve this behavior and every time when some field is resized we have to loop through all levels and fields and to set their width manually. For big amount of data, it is extremely possible this action to lead to performance issues.
What I can suggest in this case is submitting a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at http://ideas.infragistics.com .
Let me know if I may be of any further assistance.