TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Scott G
NA
103
7.7k
Weird issues when adding to a winform listbox
Aug 23 2019 11:12 AM
I have an application that allows the user to select a file and display the folder\filename in a listbox. The problem I am having is when it adds it to the listbox it adds a blank row above it. This is causing a second row to be created in the database with this field being blank. This only happens though with the first file selected. If I go back to add another one it does not add the blank row. It also does not happen if I select multiple files at once to add. In addition to that if I minimize then maximize the application any items listed in the listbox are duplicated.
private
void
btnModSel_Click(
object
sender, EventArgs e)
{
System.IO.Stream myStream;
OpenFileDialog openFiledialog1 =
new
OpenFileDialog();
openFiledialog1.FilterIndex = 2;
openFiledialog1.InitialDirectory =
"P:\\Folder\\subfolder"
;
openFiledialog1.RestoreDirectory =
true
;
openFiledialog1.Multiselect =
true
;
openFiledialog1.Title =
"Please Select a File"
;
if
(openFiledialog1.ShowDialog() == DialogResult.OK)
{
foreach
(String file
in
openFiledialog1.FileNames)
{
try
{
if
((myStream = openFiledialog1.OpenFile()) !=
null
)
{
using
(myStream)
{
lstModFiles.Items.Add(file.Substring(52));
}
}
}
catch
(Exception ex)
{
MessageBox.Show(
"Error: Could not read file from disk. Original error: "
+ ex.Message);
}
}
}
}
Reply
Answers (
7
)
Datatable data export to PDF
devExprss Disable editing for DateEdit control inside gridvi