0

Created a Core 3.0 Winforms project. I have no issues with button clicks etc however the Listview doesn't send any events like click.

I used the sample found here, that seems to work okey, however my events on a Listview are not happening.

Even a simple assignment in the forms constructor is not Propagation.

public Form1()
{
 ListViewControlItems.Click += ListViewControlItems_Click;
}

private void ListViewControlItems_Click( object sender, EventArgs e)
{
    throw new NotImplementedException();
}

I can click all like, no exception, no brakepoint gets hit. Source can be downloaded here

Walter Verhoeven
  • 3,867
  • 27
  • 36
  • I've tried it in NETCORE3. `Click` event of `ListView` works as expected. Make sure you have registered the event handler correctly. Make sure you are seeing the same list view which you subscribed for its events. If you are looking for some workaround for design-time support, take a look at [this post](https://stackoverflow.com/a/53976235/3110834). – Reza Aghaei Aug 12 '19 at 08:21

1 Answers1

0

so Tobias found a work arround for the bug in GitHub. Looks like that, for now, you may get an issue when you alter the ListView in the constructor of the form.

After I moved the initialization of the Listview in the form from the constructor to the Load event the issue of it not firing events was solved. From BAD!

public Form1()
{
    InitializeComponent();
    columnWidths = new Dictionary<string, int>
    {
        ["DirectoryName"] = 150,
        ["TrainingError"] = 150
    };

    columnAlighnments = new Dictionary<string, HorizontalAlignment>
    {
        ["DirectoryName"] = HorizontalAlignment.Left,
        ["NetworkConfiguration"] = HorizontalAlignment.Left
    };

    ListViewControlItems.Columns.Clear();
    foreach (string columnName in ListViewHeaders())
    {
        ListViewControlItems.Columns.Add(columnName
                                        , width: columnWidths.TryGetValue(columnName, out int i) ? i : 50
                                        , textAlign: columnAlighnments.TryGetValue(columnName, out HorizontalAlignment a) ? a : HorizontalAlignment.Right);
    }
    ListViewControlItems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

    ListViewControlItems.SelectedIndexChanged += OnSelectedTrainingFileChanged;

    fileSorter = new ListViewColumnSorterExt(ListViewControlItems);

}

to work around:

public Form1()
{
    InitializeComponent();
    columnWidths = new Dictionary<string, int>
    {
        ["DirectoryName"] = 150,
        ["TrainingError"] = 150
    };

    columnAlighnments = new Dictionary<string, HorizontalAlignment>
    {
        ["DirectoryName"] = HorizontalAlignment.Left,
        ["NetworkConfiguration"] = HorizontalAlignment.Left
    };

    Load += OnFormLoaded;

}

private void OnFormLoaded(object sender, EventArgs e)
{

    ListViewControlItems.Columns.Clear();
    foreach (string columnName in ListViewHeaders())
    {
        ListViewControlItems.Columns.Add(columnName
                                        , width: columnWidths.TryGetValue(columnName, out int i) ? i : 50
                                        , textAlign: columnAlighnments.TryGetValue(columnName, out HorizontalAlignment a) ? a : HorizontalAlignment.Right);
    }
    ListViewControlItems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

    ListViewControlItems.SelectedIndexChanged += OnSelectedTrainingFileChanged;

    fileSorter = new ListViewColumnSorterExt(ListViewControlItems);

}
Walter Verhoeven
  • 3,867
  • 27
  • 36