DevExpress GridControl ColumnAutoWidth - wpf

The question is probably silly, but I spent half of the day looking for the answer with no luck.
I have a WPF view with DevExpress GridControl included (not developed by me). The problem is that when I click "Auto fit" option - it gets too wide with a horizontal scroll. The reason is long header titles, but it's Ok if they are wrapped into 2 lines.
After some searching, I thought that what I need is ColumnAutoWidth property. The problem (here goes the silly part) is that I can't find out how to set it! Because of this I can't check if it works at least! There are no examples in documentation, and code autocomplete doesn't show it's presence anywhere. I had some assumptions but they appeared to be wrong.
Can somebody please share XAML (or at least code-behind) example about how to access this property?

you just have to remove width element from your columns, and to set the autowidth element of the tableview. the link you posted is related xtraGrid control and it is a windows form not a WPF one, you have to control the width from the TableView.AutoWidth property.
Try to read the following documentation

Your link is documentaion for WinForms grid. For Wpf GridColumn http://documentation.devexpress.com/#WPF/DevExpressXpfGridGridColumnMembersTopicAll
As I understand you question - you want to fix column width. Try this
<dxg:GridColumn Header="MyAwesomeColumn"
Width="40"
FixedWidth="True"
FieldName="MyFieldName" />

Related

How to use a control equivalent to the WinForms DataGridView in WPF

I've been creating an inspection form using WPF and I need a place where users can type an unknown amount of comments (hence why I'm not using textboxes). In my WinForms version of this application, I used a DataGridView and I could enter in as much information as I wanted to. I'm looking to do the same with a DataGrid or an equivalent control in WPF.
WinForms Example
I need to be able to do the same thing in WPF but I can't seem to add any rows in the DataGrid. On top of that, when I try to check CanUserAddRows it unchecks it immediatly.
So I checked out Vincent Sigal's blog post about this issue. He mentions something interesting:
... but beware of CanUserAddRows and CanUserDeleteRows as they can appear a little magical. Their values are coerced based on other properties such as DataGrid.IsReadOnly, DataGrid.IsEnabled, IEditableCollectionView.CanAddNew, and IEditableCollectionView.CanRemove. So this is another thing to watch out for when editing. If you run into a situation where you set CanUserAddRows or CanUserDeleteRows to true but it is changed to false automatically, check that the conditions below are met.
I verified this and my DataGrid is not read-only and it is enabled. Although, I have no idea where to find the IEditableCollectionView.CanAddNew and IEditableCollectionView.CanRemove ...
I don't think my situation should require a binding event on the DataGrid since the user is supposed to enter his comments directly into the DataGrid ... Is what I'm trying to do even possible? Perhaps I should use a different control?
I have to admit that I stopped reading through your question after the first paragraph, so please forgive me if I have understood you wrong... but if you just want to enter multi line text into a TextBox in WPF, you can do it by setting a couple of properties on it:
<TextBox TextWrapping="Wrap" AcceptsReturn="True" />
For a DataGrid, you can set these properties in the DataGridTextColumn.ElementStyle and/or DataGridTextColumn.EditingElementStyle as the WPF DataGridTextColumn multi-line input post shows quite nicely.
Please let me know if I did misunderstand you.
UPDATE >>>
Ok, so I came back to read the rest of your question... answering without reading the question can be risky business on this site. It's just as well that I did too, as I see you also want to know how to use the DataGrid.
I have to start by saying... take a deep breath... WPF is very different to WinForms... very different. In WPF we manipulate data rather than UI objects, so to add a new row actually means adding a new item to a collection. You can find a complete working example on the DataGrid Class page on MSDN.
Please also view the WPF DataGrid Control page on WPF Tutorial.NET for more examples. WPF has a lot to take in for new comers and can be quite bewildering, but it's well worth the trouble when you get into it.

Can't set the table width in WPF through

I am making WPF application.I have a data grid and all columns have set their width to "Auto".When i start scrolling through the table some of the columns start expanding.My question is: Can I set the column width to fit the longest data in column at the beginning (without expanding columns when i scroll)?
the column width for wpf expanding when the shown data need more space when it set to Auto then this work will be done automatically.
Well this is due to the virtualization of the DataGrid. Only the items, which are visible are rendered and the controls are reused in case of scrolling (if you are activating it). And so the width will not be correct, since the longest element is not rendered yet. A list control performs very well, although you might bind many items to it.
I think you have 2 options
Turning off the virtualization, which might be a proper solution, if you don't have many items to show. I've to admit, I didn't try it, so no warranty. You can turn it off via <DataGrid VirtualizingStackPanel.IsVirtualizing="False"/>. For more information on the VirtualizationStackPanel pls have a look here.
Another solution may be TextTrimming. TextBlocks can show Ellipses if the text is too long. Therefor you will have to assign a custom datatemplate to the column put the following as content e.g. <TextBlock Text="{Binding}" TextTrimming="WordEllipsis"/>. Please note, that you will also have to provide a customer CellEditingTemplate, if the user shall be able to edit the values. For more information about TextTrimming please have a look here. To get an idea how the whole DataTemplate thing regarding DataGrids will work, you can have a look here.

positioning of elements in xaml

I have 2 ListPicker's.
For example:
<toolkit:ListPicker FullModeItemTemplate="{Binding lpkFullItemTemplate}" ItemTemplate="{Binding lpkItemTemplate}"
x:Name="lpkIcon">
</toolkit:ListPicker>
<toolkit:ListPicker FullModeItemTemplate="{Binding lpkFullItemTemplate}" ItemTemplate="{Binding lpkItemTemplate}"
x:Name="lpkWhen">
</toolkit:ListPicker>
This Listpickers are located near. When i am click on first listpicker it shows the menu, but its covered by the second listpicker.
I tried to disable the visibility of second listbox when i click on first, but i think everything can be done through the xaml.
sorry for really stupid question and thanks.
I'm presuming you're talking about when the ListPicker is NOT in full mode (which opens in full screen).
How the two list pickers will interact visually will ultimately depend on the type of panel they're both contained in. So I can't give you a better answer unless I know which Panel you're using.
I use a lot of List Pickers in one of my apps To Do Today and my best suggestion is to use a Stack Panel wrapped with a Scroll Viewer.

WPF Datagrid column resizing upon changing FontSize

I am having an unexpected issue with DataGrid resizing.
Here is the situation: one of my application requirements is that users can change all my DataGrid's FontSize on-the-go. The grid should therefore be updated accordingly.
My columns are all defined to Auto-resize. The problem is: when I increase the FontSize, the DataGrids are correctly resized.
However, when I decrease FontSize, all rows resize appropriately, but the column headers just keep their current size!
I'd say that the auto-resizing method is strange in this case, I mean, why shouldn't it juste resize the column like it did with the rows?
FYI, I'm working under .NET 3.5 & WPFToolkit's DataGrid.
Hmmm... I haven't dealt with the specific issue you're having. But there was a similar problem I ran into and the corresponding solution I came up with.
The DataGrid is great at increasing its column sizes when needed... but struggles with decreasing them. I'm surprised that the rows shrink correctly for you... (I'm guessing something with the font size changing causes a re-calculation). But I'm guessing to get the column-headers you're going to have to manually force an layout refresh as suggested in the link provided above.
Hopefully, the approach above will also work for your specific problem. Or at least maybe you find something useful from that.

wpf - listview - how do I add an extra header row to provide a visual grouping of related fields? (ie: Grid Band)

I've got a wpf listview doing the gridview thing and I was wondering how I could add an extra header row above the field's headers?
I need to do this because this gridview shows a LOT of columns, all somewhat related to processes in a warehouse environment. The extra header provides a quick "Visual Grouping" of which fields in the grid are related.
In winforms world on 3rd party grid's they call this extra header row a "Band". I searched around but didn't see anything like this posted.
After posting here and on msdn about overriding a controltemplate to add in this extra header row I got no responses.
So I had to implement my functionality with labels stacked in a grid. I used dependency properties on my View and callback functions to handle size events and set the appropriate label width. I posted another question about this on here.
A bit hacky feeling, but it works until I can determine a better method.

Resources