`ListView.AutoResizeColumns` prevents control from firing events
See original GitHub issueFrom @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: aspnet/AspNetCore#13035
Issue Analytics
- State:
- Created 4 years ago
- Comments:24 (11 by maintainers)
Top Results From Across the Web
c# - How to prevent immediate firing of MouseUp event in ...
ListView mouse event processing in WndProc is a bit complicated. This is what I could do by overriding OnMouseUp and WndProc to stop...
Read more >In this article
The following code example demonstrates initializing a ListView in detail view and automatically resizing the columns using the AutoResizeColumns method.
Read more >ListView Class (Windows.UI.Xaml.Controls)
Gets or sets a value that indicates whether items in the view fire an ItemClick event in response to interaction. (Inherited from ListViewBase)....
Read more >ListView (JavaFX 8)
This event handler will be fired when the user cancels editing a cell. ObjectProperty<EventHandler<ListView.EditEvent<T>>>, onEditCommit. This property is used ...
Read more >ListView Control - prevent change to column widths
Other than not displaying them, is there a way to prevent the user from changing the column widths when in 'Report' mode?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve narrowed it down to
ListViewControlItems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);call. If you comment it out - everything will work as expected.Verified with latest .NET Core 3.0 Preview 9 3.0.100.14004 build, it’s not reproduced for now.