Hello everybody,
I got my machine back after the hard disk has been changed.
I improved a few programs, everything OK.
I developed a program to list the files in a directory, the user wants the second line of the file to be listed, it was no problem to display that in a RichTextBox (except I should like to have a column in a different font, but perhaps I did not choose the good control for that).
Here is now where things become serious, whereas I think it should be simple.
I want to add the file names in a ListView, and I obtain a division by zero error at the third one, and I do not understand why.
So, I created a new project named TestListView, WinForms based on .Net 4.7.2, on the form I added a ListView and a button, with this code for the button :
The two first items are added OK, at least I presume as they do not appear on the screen, but for the third element, the try...catch is ignored and I get a divide by zero error on line 7.
So I tried with the visual interface, and I also got an error when attempting to create the third element. Then I could insist, and create other elements after ignoring the error, but the application has the exception when starting.
After that, in the development interface the ListView has this aspect :
I saw nothing interesting in the eventViewer, uninstalled and reinstalled .Net desktop workload from Visual Studio 2022 (the "Framework" one, and the other one), nothing changed.
Anything I missed ?
I got my machine back after the hard disk has been changed.
I improved a few programs, everything OK.
I developed a program to list the files in a directory, the user wants the second line of the file to be listed, it was no problem to display that in a RichTextBox (except I should like to have a column in a different font, but perhaps I did not choose the good control for that).
Here is now where things become serious, whereas I think it should be simple.
I want to add the file names in a ListView, and I obtain a division by zero error at the third one, and I do not understand why.
So, I created a new project named TestListView, WinForms based on .Net 4.7.2, on the form I added a ListView and a button, with this code for the button :
Inserting items in a ListView with a button:
private void btnAddItems_Click(object sender, EventArgs e)
{
for(int i = 0; i < 10; i++)
{
try
{
listView1.Items.Add(i.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
The two first items are added OK, at least I presume as they do not appear on the screen, but for the third element, the try...catch is ignored and I get a divide by zero error on line 7.
So I tried with the visual interface, and I also got an error when attempting to create the third element. Then I could insist, and create other elements after ignoring the error, but the application has the exception when starting.
After that, in the development interface the ListView has this aspect :
I saw nothing interesting in the eventViewer, uninstalled and reinstalled .Net desktop workload from Visual Studio 2022 (the "Framework" one, and the other one), nothing changed.
Anything I missed ?
Last edited: