Skip to content

ListView Control on a WinForms project does not fire events #13035

Closed

Description

@PeterPann23

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:

  1. Visual Studio 2019, Core 3.0 Release 3.0.100-preview7-012821
  2. 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();
	}
}
  1. 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

Capture

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]

Activity

  1. Pilchie commented on Aug 11, 2019

    @Pilchie
    Member

    This issue was moved to dotnet/winforms#1607

  2. locked and limited conversation to collaborators on Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions