简体   繁体   English

如何使用Windows窗体在datagridview中显示计数

[英]How to display the count in datagridview using windows forms

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. 假设如果未插入40个文件,则需要单击“确定”按钮40次。 I need to display the files which are inserted and which are not inserted at a time in a datagridview. 我需要在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);
}

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. 要在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;
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM