Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selected item no longer working in 4.0.2 #170

Closed
HarborIntex opened this issue Apr 12, 2024 · 21 comments
Closed

Selected item no longer working in 4.0.2 #170

HarborIntex opened this issue Apr 12, 2024 · 21 comments

Comments

@HarborIntex
Copy link

I updated by project to the latest stable 4.0.2 and all my grids lost the ability to select items.
After testing and debugging - I downloaded the full 4.0.2 code ZIP and ran the sample and it also is not working in the sample.
Tested with Android local device and emulator.

Anyone else?

@andreptcosta
Copy link

same problem here

@symbiogenesis
Copy link
Collaborator

symbiogenesis commented Apr 12, 2024

Try setting the <MauiVersion> to 8.0.6

@symbiogenesis
Copy link
Collaborator

Fixed with #171

@lendres
Copy link

lendres commented Apr 17, 2024

This is fantastic, thanks for the fix. I've downloaded, compiled, and tested this update with 8.0.20 and the selection seems to be working.

@andreptcosta
Copy link

@lendres I tried using 8.0.20 and 4.0.3 and it still doesn't work. I ran the test project and it didn't work either. What did you do differently?

@andreptcosta
Copy link

@HarborIntex Can you check if the problem has been fixed? I updated to 4.0.3 with MAUI 8.0.20 and ItemSelected still doesn't fire

@lendres
Copy link

lendres commented Apr 19, 2024

@lendres I tried using 8.0.20 and 4.0.3 and it still doesn't work. I ran the test project and it didn't work either. What did you do differently?

I downloaded the repo and compiled it. I just tried it by installing 4.0.3 from NuGet and it does seem to be working for me. I tested the sorting and that the selected item was correctly printed to the output window. That is, from the demo, the function in MainViewModel.cs

    private void CmdTapped(object item)

    {
        if (item is Team team)
        {
            Debug.WriteLine($"Item Tapped: {team.Name}");
        }
    }

correctly prints the selected item. I'm not sure what you mean by "ItemSelected still doesn't fire." Is that specific to your code or in the demo app?

@andreptcosta
Copy link

@lendres There is the ItemSelected eventhandler in DataGrid, where the selected item function worked until 4.0.1.

Yes RowTappedCommand works but EventHandler ItemSelected does not

@lendres
Copy link

lendres commented Apr 19, 2024

I hooked onto the ItemSelected event and it triggers.

If you feel it is not working, I'd suggest posting a separate issue with a minimum working example.

@HarborIntex
Copy link
Author

@HarborIntex Can you check if the problem has been fixed? I updated to 4.0.3 with MAUI 8.0.20 and ItemSelected still doesn't fire

Sorry got pulled onto another project last week and this sat on the burner.
Upgraded and no - I am getting the same thing as you - my ItemSelected does not fire.

In my code behind of my form I simply have:
grdPallets.ItemSelected += grdPallets_ItemSelected;

private void grdPallets_ItemSelected(object sender, EventArgs e)
{
// do cool stuff.

}

This worked fine up to 4.0.1 - but no longer.
I see @lendres says it works for him. Can you show your code?

I can change my code to RowTappedCommand - but if the ItemSelected trigger still works - I would prefer to just correct my existing code.

akgulebubekir added a commit that referenced this issue Apr 25, 2024
this test added to make sure that #170 has been fixed.
@akgulebubekir
Copy link
Owner

@HarborIntex I've created 2 unit test cases to make sure its working properly. So far I couldn't reproduce. Please let us know if you can.

@lendres
Copy link

lendres commented Apr 25, 2024

I cannot reproduce it either. I've tested it by hooking it up from both the xaml and code-behind and both work for me. I think it would be best to post a minimum working example where you are having the issue.

@HarborIntex
Copy link
Author

DGSelectedItemTest.zip

Attached is VERY simple test application. In 4.0.1 the ItemSelected event fires. Upgrade to 4.0.3 and it does not.
image

Here is he code behind for the main form.

The only thing I change from version to version is:
SelectionEnabled="True" to SelectionMode="Single"

using System.Data;
using DGSelectedItemTest.ViewModels;

namespace DGSelectedItemTest
{
public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();
        grdTest.ItemSelected += GrdTest_ItemSelected;

        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        DataRow dr = dt.NewRow();
        DataColumn  dc = new DataColumn();

        dc.ColumnName = "Test";
        dc.DefaultValue = "Testing";
        dt.Rows.Add(dr);
        dt.Columns.Add(dc);
        ds.Tables.Add(dt);

        BindingContext = new TestViewModel(ds);

    }

    private void GrdTest_ItemSelected(object? sender, SelectionChangedEventArgs e)
    {
        DisplayAlert("Simple DG Test", "Works with 4.0.1", "Ok");
    }

   
}

}

@lendres
Copy link

lendres commented Apr 26, 2024

I tested your code as you uploaded it with only one change, I used a "Windows Machine" (I don't have a working Android emulator installed) and it work (DataGrid v4.0.3, Maui Controls 8.0.21).

If you are able to test on a Windows platform, could you please try that and see if there is a difference?

datagrid-test

@HarborIntex
Copy link
Author

HarborIntex commented Apr 26, 2024

Thanks for testing.
It does work for Windows - but also does not work with Android Emulator (Pixel 5 api 33).
I am developing against a Zebra Android 13 device. So, for me it does not work on either the Android emulator or a local device - but does work against Windows.

@HarborIntex
Copy link
Author

@symbiogenesis @lendres either of you able to recreate this with Android with my example? I see the "solution" to 176 above was to rollback to .01. I don't want to do that. Can this not be reopened?

Again - my example is as simple as you can get and does not work on Android native or Emulator. Windows does work - but I have no need for that.

@lendres
Copy link

lendres commented May 2, 2024

@HarborIntex This issue was originally for the selected item which has been fixed and so the issue was closed. I would suggest submitting this as a new issue and including your example for Windows and Android.

@symbiogenesis
Copy link
Collaborator

symbiogenesis commented May 2, 2024

@HarborIntex There were a lot of problems with your sample app. But after correcting all of them, there was still a problem.

PR #163 introduced RowTappedCommand via a gesture recognizer

If I remove that gesture recognizer and then run your sample app, then it works.

So, for now, until a hotfix is released, I recommend using a project reference to the DataGrid project. And then just remove the following lines from the DataGrid XAML code of this library:

<local:DataGridRow.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding RowTappedCommand, Source={x:Reference self}}" CommandParameter="{Binding .}" />
</local:DataGridRow.GestureRecognizers>

Alternatively, you could stick with 4.0.3 and try to use the RowTappedCommand which is more MVVM-style anyways.

@symbiogenesis
Copy link
Collaborator

symbiogenesis commented May 2, 2024

Here were the biggest errors with your app, for your own future reference:

  • The SelectedItem was set the same as the ItemsSource. Instead, you should have a single SelectedTestItem property and a TestItems collection

  • The DataType annotation on the CellTemplate was wrong. It should have been set to string, not the ViewModel.

@symbiogenesis
Copy link
Collaborator

@HarborIntex also you don't need to open another issue, because someone already had opened one that pinpointed the issue

#175

@HarborIntex
Copy link
Author

Works with 4.04 with no changes - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants