[英]how do I display time in a windows forms dataGridView bound to a datatable
[英]How to display the count in datagridview using windows forms
在我的應用程序中,如果文件上傳成功,我將顯示消息,同時,我將在消息框中顯示未上傳文件的消息。
問題是,每次出現消息時,我都需要單擊消息框中的“確定”按鈕。 假設如果未插入40個文件,則需要單擊“確定”按鈕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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.