Home Forums WPF controls Xceed DataGrid for WPF Disable sorting, disable Column drag/drop

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22437 |

    Hi,

    I have implemented a three column data grid, but would like to disable the sorting. I have the following xaml to define the grid, which works fine

    <xcdg:DataGridControl.ItemsSource >
    <d:Binding>
    <d:Binding.Source>
    <CollectionViewSource x:Name=”item_collection” Source=”{Binding Source={x:Static Application.Current},Path=MassGrid}”>
    <CollectionViewSource.SortDescriptions>
    <scm:SortDescription PropertyName=”Q1 Mass” Direction=”Descending”/>
    </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>
    </d:Binding.Source>
    </d:Binding>
    </xcdg:DataGridControl.ItemsSource>

    But when I set the Direction=”None”, it bombs at runtime. Not surprising since the underlying .net type only supports Ascending and Descending. So how to disable sorting? Do I just setup an eventhandler to react to the click of the Header and do nothing? Is there a way do do this in Xaml? The SortIndex Property on Column is readonly…

    I have found that I can disable the “Helper” heading “Drag column header…” programmatically like this:
    theView.FixedHeaders.RemoveAt(0); Is there a way to do this in Xaml?

    Finally, I would like to disable drag/drop column reordering – how does one go about doing this?

    Once I’m done with my sample, I am willing to share the code with the community (if my boss allows it).

    Friedrich

    Imported from legacy forums. Posted by Friedrich (had 7458 views)

    Xceed Support
    Member
    Post count: 5658

    Quote:
    <i>Do I just setup an eventhandler to react to the click of the Header and do nothing?</i>

    That’s effectivelly the easiest solution, you can handle the PreviewMouseButtonDown event and prevent sorting/grouping that way.

    Also, to remove the GroupByControl in XAML, the only solution is to first “clear” all the headers and then re-add those you want:

    <code>
    <xcdg:TableView.FixedHeaders>
    <xcdg:ClearHeadersFooters/>

    <!– re-add those you want here –>
    </xcdg:TableView.FixedHeaders>
    </code>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 808 views)

    User (Old forums)
    Member
    Post count: 23064

    Marc,

    Clearing and re-adding does work – it just took me a bit of time to figure it out 😉 The code is below.

    One more question: if I disable messages to the ColumnManagerRow, I still get the resizer column width resizer icon when I move the mouse over the Thumbs part. Is there a simple way to disable that change of icon, or does one have to replace the control template?

    What if I wanted to only disable sorting, or moving the columns, or resizing the columns?

    — This is the code you need to just have the one columnmanagerRow with all the header stuff disabled. Disables sorting, moving the columns, resizing etc.

    // xaml, inside data grid control
    <xcdg:DataGridControl.View>
    <xcdg:TableView Name=”theView”>
    <xcdg:TableView.FixedHeaders>
    <xcdg:ClearHeadersFooters/>
    <DataTemplate>
    <xcdg:ColumnManagerRow PreviewMouseLeftButtonDown=”theView_PreviewMouseLeftButtonDown”/>
    </DataTemplate>
    </xcdg:TableView.FixedHeaders>
    </xcdg:TableView>
    </xcdg:DataGridControl.View>

    // code behind
    void theView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
    e.Handled = true;
    }

    P.S. That snoop tool is wonderful and scary at the same time. It shows how incredibly complex the grid really is (how many details you have to worry about…)

    Bonjour a toute la gang de Frederique a Toronto
    F.

    Imported from legacy forums. Posted by Friedrich (had 1408 views)

    Xceed Support
    Member
    Post count: 5658

    Bonjour de Montréal et merci pour tes salutations.

    Concerning your questions:

    The easiest way to get rid of the Column Resizer “icon” (and get rid of the resizing as well) if to ensure that the columns are “fixed size”… To do this, set their MaxWidth equals to their MinWidth ( and equals to their Width, for consistency purpose). Doing this will ensure that the column is not resizeable (and cursor will not change)…

    At the same time, if you’d like to selectively enable/disable features like sorting and/or grouping (while retaining other features). I advise ensuring that you wrap your data source in a collection view that returns appropriate values for the “CanSort” and “CanGroup” properties (then, there will be no need to hook to the PreviewMouseLeftButtonDown).

    If you do wrap your data source in a collection view, the ColumnManagerCells will still handle clicks and drag, but it will have no effect. This can be done in conjunction with the MinWidth/MaxWidth trick.

    At the same time, it is already in our plans to place properties on the Column class to determine if Grouping and Sorting can be done via UI (remember that we cannot forbid programmatic access to grouping and sorting, if your data source supports it).

    I have noted a feature request concerning you request to prevent “moving” the columns. This is something that is currently not supported.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 836 views)

    User (Old forums)
    Member
    Post count: 23064

    Marc,

    MinWidth/MaxWidth works great. I may try the CollectionView wrap of the datasource if I need it.

    je voudrais bien t’envoyer un example (seulement a titre de demonstartion!) que j’ai construit avec le data grid de xceed. Il illustre bien l’usage qui convient a nos clients. L’example fonctionne avec le controle courrant, mais certaines choses pourraient etre fait au niveau du controle pour faciliter la construction d’un programme comme mon example. Si tu peux m’envoyer un court message a brunzefb_AT_yahoo.com (enleve le _AT_), je t’envois mon code example.

    Friedrich

    Imported from legacy forums. Posted by Friedrich (had 4417 views)

    User (Old forums)
    Member
    Post count: 23064

    [quote user=”Marcus”]Quote:
    <i>Do I just setup an eventhandler to react to the click of the Header and do nothing?</i>

    That’s effectivelly the easiest solution, you can handle the PreviewMouseButtonDown event and prevent sorting/grouping that way.

    Also, to remove the GroupByControl in XAML, the only solution is to first “clear” all the headers and then re-add those you want:

    <code>
    <xcdg:TableView.FixedHeaders>
    <xcdg:ClearHeadersFooters/>

    <!– re-add those you want here –>
    </xcdg:TableView.FixedHeaders>
    </code>

    [/quote]

    Ok so if I want to prevent the sort by listening to the header event in the PreviewMouseDownButton, how do I do it? Can yuo give me some code snippet? When I catch the event I can’t figure out if the mouse was down on the header or on a cell. If it was on a cell the event should continue as normal, only on the header must it be ignored.

    Imported from legacy forums. Posted by Marthinus (had 2388 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.