Reputation: 263
private int numberofallmessages = 0;
private int countMsg = 0;
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
OpenPop.Pop3.Pop3Client PopClient = new OpenPop.Pop3.Pop3Client();
PopClient.Connect("mail", 110, false);
PopClient.Authenticate("me", "me",
OpenPop.Pop3.AuthenticationMethod.UsernameAndPassword);
int messageCount = PopClient.GetMessageCount();
numberofallmessages = messageCount;
allMessages = new List<OpenPop.Mime.Message>(messageCount);
for (int i = messageCount; i > 0; i--)
{
if (backgroundWorker1.CancellationPending == true)
{
e.Cancel = true;
return;
}
allMessages.Add(PopClient.GetMessage(i));
int nProgress = (messageCount - i + 1) * 100 / messageCount;
backgroundWorker1.ReportProgress(nProgress, PopClient.GetMessageCount().ToString() + "/" + i);
}
PopClient.Disconnect();
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
pbt.Value = e.ProgressPercentage;
pbt.Text = e.ProgressPercentage.ToString() + "%";
pbt.Invalidate();
label8.Text = e.UserState.ToString();
label8.Visible = true;
lstMail.Items.Add(allMessages[countMsg].Headers.Subject + " " + allMessages[countMsg].Headers.DateSent);
countMsg += 1;
}
In the ProgressChanged event i'm adding the items to the listView(lstMail).
lstMail.Items.Add(allMessages[countMsg].Headers.Subject + " " + allMessages[countMsg].Headers.DateSent);
But this line will keep adding also the DateSent to the first tab and not to the date tab:
There is a subject tab and a date tab and i want that the part
allMessages[countMsg].Headers.DateSent
Will be under the date tab.
Upvotes: 1
Views: 405
Reputation: 1
This is the standard way of adding items to columns in a listView.
ListViewItem item1 = new ListViewItem("Something");
item1.SubItems.Add("SubItem1a");
item1.SubItems.Add("SubItem1b");
item1.SubItems.Add("SubItem1c");
ListViewItem item2 = new ListViewItem("Something2");
item2.SubItems.Add("SubItem2a");
item2.SubItems.Add("SubItem2b");
item2.SubItems.Add("SubItem2c");
ListViewItem item3 = new ListViewItem("Something3");
item3.SubItems.Add("SubItem3a");
item3.SubItems.Add("SubItem3b");
item3.SubItems.Add("SubItem3c");
ListView1.Items.AddRange(new ListViewItem[] {item1,item2,item3});
Also see: C# listView, how do I add items to columns 2, 3 and 4 etc?
Upvotes: 0
Reputation: 15982
Change this line:
lstMail.Items.Add(allMessages[countMsg].Headers.Subject + " " + allMessages[countMsg].Headers.DateSent);
To:
lstMail.Items.Add(new ListViewItem(new string[]
{
"", //From Column
allMessages[countMsg].Headers.Subject, //Subject Column
allMessages[countMsg].Headers.DateSent.ToString() //Date Column
}));
Hope this helps.
Upvotes: 1