C# 如何使用windows窗体在datagridview中显示计数

C# 如何使用windows窗体在datagridview中显示计数,c#,datagridview,C#,Datagridview,在我的应用程序中,如果文件上载成功,我将显示消息,同时在消息框中显示未上载的消息 问题是每次当消息出现时,我都需要单击消息框中的“确定”按钮。假设没有插入40个文件,我需要点击ok按钮40次。我需要在datagridview中显示一次插入和未插入的文件。我怎样才能做到这一点 if (ErrorMessage == 0) { Ffname += path + "-" + "Uploaded successfully" + "\n"; } else { NotInsFiles +=

在我的应用程序中,如果文件上载成功,我将显示消息,同时在消息框中显示未上载的消息

问题是每次当消息出现时,我都需要单击消息框中的“确定”按钮。假设没有插入40个文件,我需要点击ok按钮40次。我需要在datagridview中显示一次插入和未插入的文件。我怎样才能做到这一点

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);
}

我认为您必须围绕您的上传文件进行循环,并且您必须在这个循环中添加

if (ErrorMessage == 0)
{
    Ffname += path + "-" + "Uploaded successfully" + "\n";
}
else
{
     NotInsFiles += path + " - " + "Not Inserted" + "\n";
}
当循环完成时,尝试显示消息框

要在datagridview中显示图像,必须插入DataGridViewImageColumn类型的列,然后才能在其中显示图像

        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;
            }
        }

单击按钮做什么?你不能把它放在计时器里吗?这不是点击按钮,而是我们在消息框中看到的按钮,这是正常的ok按钮Well yes,因为messagebox.show将停止代码,直到你响应它…是的,我需要在datagridview中最终绑定它们,而不是在消息框中显示假设我上载了40个文件,并在其中插入了15个文件和25个未插入我需要在datagridview中显示它们,有两列,分别为inserted和not inserted和in inserted我需要显示这15个文件,而在not inserted中我需要显示25个文件,这25个文件也需要显示。似乎您正在寻找一种方法来记录您的程序所采取的操作,为什么不创建一个包含这些消息的列表,或者一个文本框,您可以将这些消息添加到其中?另外,这里显示的代码是foor循环的一部分吗?我需要在datagridviewlook中显示已上载和未上载的文件