I have a grid that should display full information for some rows and only basic info and description for the others. E.g. there is a number, a description field and details after it for rows of type A and there's just a number and a description for a row of type B. The description field should extend till the end of the row and cover not relevant cells. The description is longer for B rows, so it makes sense for this column to be wide. All objects in a collection are of the same C# type, but there's a property that returns the type A or B. What are my choices? Would multiple fieldlayouts be a way? How? I also want the grid to always use the field descriptions from the A row even if the first row is B. I'd prefer XAML only solution, but I'll take whatever I can get :) Any ideas? Thanks.
So I am one step further. In code behind I used an AssigningFieldLayoutToItem event to set a different fieldlayout based on the type property. But I got header labels for each group of layouts. Which I got rid of by setting LabelLocation="Hidden" in FieldLayoutSettings. So the data looks exactly as I want it, but I have no labels now :) Is there a way to force one particular fieldlayout to create a header with labels? It would be enough if they just sat there, with no sorting or whatever functionality. I could even live with the columns not being resizable if it made things easier, but zooming in and out should keep the labels and cells synchronized.
Ivan
Hello Ivan,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically I used additional FieldLayouts with visible Labels. One of them is assigned to the first Record. After that the FieldLayouts with the hidden labels are used. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
Here's an idea. I could add a dummy row at the beginning of the collection, use the full layout for it, and set the record's visibility to Hidden in InitializeRecord. Now it's almost perfect, but I need to get rid/reduce the space occupied by the hidden row. I cannot set it to collapsed, because then the labels are gone, too. Do you have a tip how to do this?
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Cool, that's all done, now. Thank you for your help and patience, Stefan.
Hello again,
You can handle the XamDataGrid's Loaded event and in the handler you can set the dummy Record to be fixed, like this:
(sender as XamDataGrid).Records[0].IsFixed = true;
Hi Stefan,
yes, that worked! Thanks. Now it looks exactly as it should. The last inconvenience is that the header with column descriptions scrolls away when there's a scrollbar. Can something be done about that? :)
You can add the following Style for the DataRecordPresenter to the XamDataGrid's Resources:
<Style TargetType="{x:Type igDP:DataRecordPresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding DataItem.Id}" Value="0"> <Setter Property="Height" Value="0"/> </DataTrigger> </Style.Triggers> </Style>
You can use a value that will be uniques for a Property of the dummy Record. In teh example the Proeprty is called "Id" and the value is "0". You can change them as per your requiremnts. Please let me know if this helps you or you have furtehr questions on this matter.