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

SelectedItems don't work #198

Open
thunderhead021 opened this issue Aug 1, 2024 · 10 comments
Open

SelectedItems don't work #198

thunderhead021 opened this issue Aug 1, 2024 · 10 comments

Comments

@thunderhead021
Copy link

Describe the bug
I have a Datagrid with an ObservableCollection as the binding for SelectedItems. I didn't given SelectionMode, but even when I give it as Multiple, it also not work. The app freeze and close.

To Reproduce
Steps to reproduce the behavior:

  1. create DataGrid
  2. add ObservableCollection A as ItemsSource
  3. add ObservableCollection B as SelectedItems

Expected behavior
The app and DataGrid should be working like normal. And rows show selected effect when ObservableCollection B is update.

Desktop (please complete the following information):

  • OS: Win11
  • DataGrid v 4.0.4
  • Maui 9.0.1
@thunderhead021
Copy link
Author

thunderhead021 commented Aug 1, 2024

Update: I also tested with IList<object> and that also not working
Update2: Tested with List<object> a = new(){}; and this error show up in the call stack
[]' cannot be converted to type 'System.Collections.Generic.List1[System.Object]'`

@VegasJohnson
Copy link

VegasJohnson commented Aug 2, 2024

It does call from your
var list = new ObservableCollection<Dataview>();

as my issue was the same. cant call from the grid have to call from the list.

`var sel = dataview.SelectedItem as Dataview;

var id = sel.Id.ToString();`

@thunderhead021
Copy link
Author

thunderhead021 commented Aug 2, 2024

It does call from your
var list = new ObservableCollection();

as my issue was the same. cant call from the grid have to call from the list.

var sel = dataview.SelectedItem as Dataview;

var id = sel.Id.ToString();`

I was doing that. Then I also try IList<object> a {get; set;} which also not working. Tried it in the example also not work as well. My work around right now is to create a helper ViewModel contain the display object, the ID of the row, bool flag to show the selected row in the View and all the operation from the IComparable similar to the streak class from the example and add it to the ViewModel display in the DataGrid. This and also have the RowTapCommand to add/remove it to a private HashSet and check it manually. The only problem I have now is when I change the infomation in that ViewModel, the data of that cell is not update at all in the View even when it's update in the ViewModel

@symbiogenesis
Copy link
Collaborator

If you fork this repo, and reproduce the issue with the contained Sample project, that would help me fix it.

thunderhead021 added a commit to thunderhead021/Maui.DataGrid that referenced this issue Aug 7, 2024
@symbiogenesis With the SelectedItems bind to IList<object> SelectedTeams and use in the view. The example won't run at all. Only when remove it from the view the example can run again
@thunderhead021
Copy link
Author

thunderhead021 commented Aug 7, 2024

@symbiogenesis I have push the example of what my problem is here is also a the output log if you want to compare it:

'Maui.DataGrid.Sample.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Maui.DataGrid.Sample.dll'. 
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Runtime.InteropServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\WinRT.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Collections.Concurrent.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Runtime.CompilerServices.Unsafe.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Private.Uri.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.ObjectModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.ComponentModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Numerics.Vectors.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.WinUI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Windows.SDK.NET.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Security.Cryptography.Algorithms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Security.Cryptography.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Memory.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.InteractiveExperiences.Projection.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Linq.Expressions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Reflection.Emit.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'Snippets'. 
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.Essentials.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.Controls.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Extensions.DependencyInjection.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.Controls.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\CommunityToolkit.Maui.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Extensions.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Extensions.Configuration.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Extensions.Primitives.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Xml.ReaderWriter.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Private.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.Graphics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Net.Primitives.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.Graphics.Win2D.WinUI.Desktop.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\CommunityToolkit.Maui.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Extensions.DependencyInjection.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Extensions.Logging.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Diagnostics.Tracing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Threading.ThreadPool.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Microsoft.Maui.Controls.Compatibility.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.Runtime.Loader.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.6\System.ComponentModel.TypeConverter.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Maui.DataGrid.Sample.exe' (CoreCLR: clrhost): Loaded 'C:\Desktop\Maui.DataGrid\Maui.DataGrid.Sample\bin\Debug\net8.0-windows10.0.22621.0\win10-x64\AppX\Maui.DataGrid.dll'. 

@symbiogenesis
Copy link
Collaborator

Could it be related to this:

dotnet/maui#8435

@symbiogenesis
Copy link
Collaborator

symbiogenesis commented Aug 7, 2024

Try using ObservableCollection<object> and then cast afterwards as needed.

Very stupid, I know. I complained about it already, in that thread.

@thunderhead021
Copy link
Author

@symbiogenesis I tried the same setup using ObservableCollection<object> which also not working for me. The same output log will always show when I put any type of list in the SelectedItems

@symbiogenesis
Copy link
Collaborator

symbiogenesis commented Aug 8, 2024

Ok, it looks like the new SR8 that came out today has this fix included:

dotnet/maui#23726

@thunderhead021
Copy link
Author

@symbiogenesis sorry for the late reply. I have now tested this with the new update . Unfortunately the app still freeze up like before. At the moment I will stick with my work around even though it's a bit annoying to update the row view separately for each column like that.

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

3 participants