Repository navigation
Closed
Labels
🪲 bugProduct bug (most likely)💥 regression-previewRegression from a preview releasetenet-compatibilityIncompatibility with previous versions or with WinForms for .NET Framework
Milestone
Description
From @PeterPann23 on Sunday, August 11, 2019 5:19:35 PM
Describe the bug
Created a new project in .net Core 3.0
Added a ListView to the form that I populate based on user actions (button click works just fine)
The events on the listview however do not get firred.
To Reproduce
Steps to reproduce the behavior:
- Visual Studio 2019, Core 3.0 Release 3.0.100-preview7-012821
- Run this the File New Windows Forms App(.Net Core) Project
My project looks like this
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.7.0-preview7.19362.9" />
<PackageReference Include="System.Windows.Forms.DataVisualization" Version="1.0.0-prerelease.19218.1" />
</ItemGroup>
</Project>The form uses the "normal" template
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
// controls before ...
this.ListViewControlItems = new System.Windows.Forms.ListView();
// other controls after ...
//
// ListViewControlItems
//
this.ListViewControlItems.Dock = System.Windows.Forms.DockStyle.Fill;
this.ListViewControlItems.FullRowSelect = true;
this.ListViewControlItems.HideSelection = false;
this.ListViewControlItems.Location = new System.Drawing.Point(0, 37);
this.ListViewControlItems.MultiSelect = false;
this.ListViewControlItems.Name = "ListViewControlItems";
this.ListViewControlItems.Size = new System.Drawing.Size(464, 413);
this.ListViewControlItems.TabIndex = 2;
this.ListViewControlItems.UseCompatibleStateImageBehavior = false;
this.ListViewControlItems.View = System.Windows.Forms.View.Details;
this.ListViewControlItems.SelectedIndexChanged += new System.EventHandler(this.OnSelectedTrainingFileChanged);
}
}the "Code Behind" part of the form is like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ListViewControlItems.Click += ListViewControlItems_Click;
}
private void ListViewControlItems_Click( object sender, EventArgs e)
{
throw new NotImplementedException();
}
}- neither the Click event or the SelectedIndexChanged event ever get invoked
Expected behavior
The button click event's get invoked without any problem, I'd expect the Listview to invoke as well. I now add a button to trigger the SelectedIndex change event and works just fine, also knows if any items are selected
private void OnSelectedTrainingFileChanged(object sender, EventArgs e)
{
if (ListViewControlItems.SelectedItems.Count > 0)
{
ConfigPropGrid.SelectedObject = ListViewControlItems.SelectedItems[0].Tag as NativeConfig;
}
else
ConfigPropGrid.SelectedObject = null;
}Screenshots
Additional context
Build output:
● Started at 19:17:54
1>------ Build started: Project: CATS.ML.Interfaces, Configuration: Debug Any CPU ------
1>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>CATS.ML.Interfaces -> D:\Source\Cats.ML\CATS.ML.Interfaces\bin\Debug\netstandard2.1\CATS.ML.Interfaces.dll
2>------ Build started: Project: Cats.Deepbook.IBApi, Configuration: Debug Any CPU ------
3>------ Build started: Project: Cats.ML.Core, Configuration: Debug Any CPU ------
4>------ Build started: Project: CATS.ML.Data, Configuration: Debug Any CPU ------
4>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
3>You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
2>Cats.Deepbook.IBApi -> D:\Source\Deepbook\Cats.Deepbook.IBApi\bin\Debug\netcoreapp3.0\Cats.Deepbook.IBApi.dll
3>ML\Data\Versatile\VersatileMLDataSet.cs(103,64,103,89): warning CS0067: The event 'VersatileMLDataSet.OnColumnsWithNoAddedValue' is never used
3>Cats.ML.Core -> D:\Source\Cats.ML\cats.ml.core\bin\Debug\netstandard2.1\Cats.ML.Core.dll
3>Done building project "Cats.ML.Core.csproj".
4>CATS.ML.Data -> D:\Source\Cats.ML\CATS.ML.Data\bin\Debug\netstandard2.1\CATS.ML.Data.dll
5>------ Build started: Project: Cats.Deepbook.Shared, Configuration: Debug Any CPU ------
5>DeeBookNativeBarBuffer.cs(42,81,42,96): warning CS0067: The event 'DeeBookNativeBarBuffer.OnCrazyMovement' is never used
5>Cats.Deepbook.Shared -> D:\Source\Deepbook\Cats.Deepbook.Shared\bin\Debug\netcoreapp3.0\Cats.Deepbook.Shared.dll
5>Done building project "Cats.Deepbook.Shared.csproj".
6>------ Build started: Project: CATS.Deepbook.NetworkTrader, Configuration: Debug Any CPU ------
6>CATS.Deepbook.NetworkTrader -> D:\Source\Deepbook\CATS.Deepbook.NetworkTrader\bin\Debug\netcoreapp3.0\CATS.Deepbook.NetworkTrader.dll
========== Build: 6 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
● Finished at 19:17:56 (total time 2.34s)
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview7-012821
Commit: 6348f1068a
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview7-012821\
Host (useful for support):
Version: 3.0.0-preview7-27912-14
Commit: 4da6ee6450
.NET Core SDKs installed:
2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
2.1.800 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
2.2.400-preview-010195 [C:\Program Files\dotnet\sdk]
2.2.400-preview-010219 [C:\Program Files\dotnet\sdk]
2.2.400 [C:\Program Files\dotnet\sdk]
3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]
3.0.100-preview7-012821 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview7.19365.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview7-27912-14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0-preview7-27912-14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Copied from original issue: dotnet/aspnetcore#13035
Metadata
Metadata
Assignees
Labels
🪲 bugProduct bug (most likely)💥 regression-previewRegression from a preview releasetenet-compatibilityIncompatibility with previous versions or with WinForms for .NET Framework
Activity
r-aghaei commentedon Aug 12, 2019
@PeterPann23 The code which you have shared doesn't reproduce the problem. The
Clickevent ofListViewwill raise if you click on an item, but I cannot see any item in your code.I've already tried the following code in VS2019, .NET CORE 3 without any problem:
RussKie commentedon Aug 12, 2019
RussKie commentedon Aug 12, 2019
@PeterPann23 please provide a repro project that exhibits the issue - either a zip or a link to a github repo will work.
Thank you
r-aghaei commentedon Aug 12, 2019
Oops! I corrected the mention. Thanks @RussKie.
PeterPann23 commentedon Aug 12, 2019
Sure
issue 1607.zip
r-aghaei commentedon Aug 12, 2019
@PeterPann23 It would be great if you can share a really simple repro, like what I shared. I couldn't use your project.
Did you give my code a try?
PeterPann23 commentedon Aug 13, 2019
@r-aghaei
I'm guessing you did not see my post just above yours. it contains a zip file with code that, on my pc does not fire the events.
r-aghaei commentedon Aug 13, 2019
@PeterPann23 In fact I tried to run it, but it has a lot of dependencies and non-relevant codes which makes it a bit hard to run and debug. That's why I posted my previous comment asking for a minimal repro if possible. Something like what I shared. Did you try the example which I shared?
PeterPann23 commentedon Aug 13, 2019
What dependencies are you referencing? I have json, that's not needed.
My code follows the normal pattern of a partial class with InitializeComponent(), actually this is auto generated code by visual studio and does not contain any 3rd party controls.
Sure, there are more controls than needed, I agree but this code contains the issue of the treeview not firing the selection changing as wel as the the onclick event on line 44.
I was asked for a sample that reproduced the problem, compile it and click… nothing happens.
weltkante commentedon Aug 13, 2019
I can confirm that the zipped project won't run as-is on the current VS 2019 preview. It has problems resolving the nuget packages and even after removing them something about the project file doesn't work out correctly. Anyways, it was pretty easy to comment all that stuff out, and the problem of no click event still repros. I'm attaching the edited project with nuget/csproj/designer items commented out, in case it helps you debugging. It probably can be reduced further by removing unnecessary UI and data files, but as it is now it shouldn't have any external dependencies beyond WinForms Core
issue 1607 (edited).zip
weltkante commentedon Aug 13, 2019
The
SelectedIndexChangedcan be made working by moving the initialization (except InitializeComponent) from constructor to Load event. This might be related to #1311 however click event still doesn't work. Removing the message box from theSelectedIndexChangedevent makes the click work too.So I can make two observations:
SelectedIndexChangedwill break the click event10 remaining items
RussKie commentedon Aug 14, 2019
I don't think we can safely implement this change without adding new quirks since it would affect existing consumers.
It is possible to call requied functionality from both handlers of
ClickandSeletedIndexchangedevents.r-aghaei commentedon Aug 14, 2019
It's not showing the
MessageBoxwhich prevents theClickevent, it's releasing the capture which prevents a mouse up and prevents a click. If you don't release the capture and close the message box using Esc key, theClickevent will raise. IMO, it's expected behavior.r-aghaei commentedon Aug 14, 2019
Also consider the following points:
In general, showing a message box in
SelectedIndexChangeddoesn't look like a good idea. The event may raise more than once. For example once for the item which get selected and once for the item which get deselected.The other thing that you should be careful about, is putting some logic in
Clickevent. Users may select items using keyboard, so the logic which you have inClickevent handler will not run in case of selecting item with keyboard.If for any reason, you want to rely on mouse events, use
MouseDown. It raises beforeSelectedindexChanged. If you want to make sure the mouse down event has been raised by keeping mouse down on an item, just check usingHitTestmethod:if (((ListView)sender).HitTest(e.Location).Item != null)PeterPann23 commentedon Aug 18, 2019
I have noted the same issue, on some other controls being Chart (KeyDown, MouseDown) and Datagridview (RowEnter), moving the binding from the AutoGenerated code called in InitializeComponent() to the Load event solves this.
weltkante commentedon Aug 19, 2019
Zheng-Li01 commentedon Aug 27, 2019
Verified with latest .NET Core 3.0 Preview 9 3.0.100.14004 build, it’s not reproduced for now.
RussKie commentedon Aug 27, 2019
Thank you!