I am trying to bind a binding list to a datagrid, with autogeneratecolumns set to true. However no columns are showing and I am wondering why.
Code snippet:
datagridResults.AutoGenerateColumns = true;
List<MailItem> mailItems = new List<MailItem>();
//readPst() returns a List<MailItem> populated with MailItems from the specified PST.
mailItems = readPst(txtBoxPST.Text, "Archive Folders");
BindingList<MailItem> bl = new BindingList<MailItem>(mailItems);
datagridResults.DataSource = bl;
datagridResults.Refresh();
The datagrid ends up being blank. I am sure that the BindingList contains the MailItems, if I changed it from binding from the BindingList to a Foreach MailItem m in bl… manually adding the rows it works fine. So my best guess is that the AutoGenerateColumns doesn’t work with the MailItem class? I am not sure why though, or the best way to work around it.
The MailItem class is the Microsoft.Office.Interop.Outlook.MailItem class.
just addToList()and don’t need to refresh theDataGridViewdatagridResults.DataSource = bl.Tolist();Update
This is how to read the
MailItemsinOutLookSource: An Introduction to Programming Outlook 2003 Using C#