MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

DataGrid unintuitive behaviour

Open ThatGuyMike7 opened this issue 3 years ago • 6 comments

Bug explanation

When I click twice on a field, its entire row becomes grey and my clicks on the field are ignored (can't edit the value), until I click on another field in another row. It seems to be very unintuitive.

I don't expect two clicks on a field to result in not being able to edit that field anymore.

I use the DataGrid like this:

<Grid>
    <TabControl TabStripPlacement="Top">
        <TabItem Header="Produkte" MaxWidth="10000">
            <StackPanel Orientation="Vertical">
                <ScrollViewer Height="300" Margin="10">
                    <DataGrid x:Name="ProductDataGrid" MinColumnWidth="50" ItemsSource="{Binding ProductData}"></DataGrid>
                </ScrollViewer>
            </StackPanel>
        </TabItem>
    </TabControl>
</Grid>

Version

4.5.0

ThatGuyMike7 avatar May 29 '22 13:05 ThatGuyMike7

I noticed the same behavior in the Demo App.

We have to clic outside the textbox do be able to edit the cell.

https://user-images.githubusercontent.com/54487782/170958020-53f7b14e-71bb-4ff9-a289-41cfb7909621.mp4

ElieTaillard avatar May 30 '22 09:05 ElieTaillard

I had the behavior in my app. I found a workaround. Set the Focusable of the ScrollViewer above the DataGrid to False.

<ScrollViewer 
   Focusable="False">
...
   <DataGrid>
...

In the Demo App, I fix this line. https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/a4a5cd21e328ce1e473811ad330a40e5f9ac1d55/MainDemo.Wpf/MainWindow.xaml#L220

However, I am not sure what the cause is.

soi013 avatar Jul 13 '22 14:07 soi013

I think setting DataGridAssist.EnableEditBoxAssist="False" resolves the issue? Unfortunately it re-establishes the double-click to edit (default) behaviour.

My uneducated guess would be that the AllowDirectEditWithoutFocus() method appears to work the first time when clicking directly on an element inside a datagrid cell, but won't work again unless the user either clicks outside of the contained element but still in the target cell, OR they click on another element in a different row.

Please confirm.

jbooth88 avatar Jul 26 '22 18:07 jbooth88

@jbooth88 I think you are right about the AllowDirectEditWithoutFocus() being the culprit. I have added a very simple PR which simply bails out of that method in case the cell is already being edited. I think this is what the user would want.

@Xaalek Could you test it out using the code from the PR (see above)?

nicolaihenriksen avatar Aug 20 '22 20:08 nicolaihenriksen

It's better than before but we still have something weird. Depending on where we click on the cell the behavior is different. I also noticed something weird with the style MaterialDesignDataGridTextColumnPopupEditingStyle. To open the edition we have to click on the edge of the cell. Moreover the pop up doesn't open at the right place. https://youtu.be/pWXAf7tRK1Q

Unfortunately, there are no specs for editable datagrids. However, we could be inspired by this library to do the job https://mui.com/x/react-data-grid/ (especially for the style with the pop up)

ElieTaillard avatar Aug 21 '22 20:08 ElieTaillard

@Xaalek I just played around with the DataGrid a bit more, and wow it really does have some strange behaviors!

I cannot reproduce the issue with the popup editing being misplaced. It opens fine on mine. I can however reproduce a bunch of different scenarios where the clicks are ignored or do not do what you would want them to.

Those issues were there before the fix in my PR, which only addresses the problem listed in this issue (i.e. the double click to edit was not working). So I guess that should not prevent the PR from being merged (you did say that "it's better than before").

Perhaps we should create another issue for sorting out the strange behaviors of the DataGrid in general?

nicolaihenriksen avatar Aug 22 '22 13:08 nicolaihenriksen

@Xaalek I think this was - for the most part - fixed in the latest release? Should we close the issue?

nicolaihenriksen avatar Nov 03 '22 17:11 nicolaihenriksen

@ThatGuyMike7 Can you reproduce the issue with the latest release? If not, perhaps the issue should be closed?

nicolaihenriksen avatar Nov 10 '22 07:11 nicolaihenriksen

Looks good to me. I just have the popup issue that is still there.

ElieTaillard avatar Nov 16 '22 09:11 ElieTaillard