Reputation: 61
In my application i am displaying the messages if file is uploaded successfully and at the same time i am displaying the message that it is not uploaded in a message box.
The problem is i need to click ok button in message box each and every time when the message occours. Suppose if 40 files are not inserted i need to click ok button for 40 times. I need to display the files which are inserted and which are not inserted at a time in a datagridview. how can i do this.
if (ErrorMessage == 0)
{
Ffname += path + "-" + "Uploaded successfully" + "\n";
}
else
{
NotInsFiles += path + " - " + "Not Inserted" + "\n";
}
lbluplodedfile.Text = TabNotIns;
if (Ffname != null || Ffname != "")
{
MessageBox.Show(Ffname);
lbluplodedfile.Text = Ffname;
}
else
{
MessageBox.Show(NotInsFiles);
}
Upvotes: 0
Views: 230
Reputation: 26
I think you have to do loop around your upload file and you have to adding in this loop the
if (ErrorMessage == 0)
{
Ffname += path + "-" + "Uploaded successfully" + "\n";
}
else
{
NotInsFiles += path + " - " + "Not Inserted" + "\n";
}
and when the loop finish try to show message box
To display image in datagridview you have to insert column of type DataGridViewImageColumn and after you can display image inside.
private void ImgToDataGridView()
{
/* List of path of img */
List<string> pathImgUpload = new List<string>();
List<string> pathNotInsert = new List<string>();
/* Just for my test */
pathImgUpload.Add("./abc.png");
pathImgUpload.Add("./abc.png");
pathImgUpload.Add("./abc.png");
pathImgUpload.Add("./abc.png");
pathNotInsert.Add("./abc.png");
pathNotInsert.Add("./abc.png");
pathNotInsert.Add("./abc.png");
pathNotInsert.Add("./abc.png");
pathNotInsert.Add("./abc.png");
/* Creation of columns for the good and bad img */
DataGridViewImageColumn colImgUpload = new DataGridViewImageColumn();
DataGridViewImageColumn colImgNotInsert = new DataGridViewImageColumn();
dataGridView1.Columns.Add(colImgUpload);
dataGridView1.Columns.Add(colImgNotInsert);
/* Max of size of pathImgUpload and pathNotInsert */
var lineadd = pathImgUpload.Count > pathNotInsert.Count ? pathImgUpload.Count : pathNotInsert.Count;
/* Create the good number of line (-1 because a first line is already in datagridview)*/
for(int i = 0; i <lineadd - 1; i++)
{
dataGridView1.Rows.Add();
}
/* adding good img */
for (int i = 0; i < pathImgUpload.Count(); i++)
{
string path = pathImgUpload[i];
var img = new Bitmap(path);
dataGridView1.Rows[i].Cells[0].Value = img;
}
/* adding bad img */
for(int i = 0; i < pathNotInsert.Count();i++)
{
string path = pathNotInsert[i];
var img = new Bitmap(path);
dataGridView1.Rows[i].Cells[1].Value = img;
}
}
Upvotes: 1